@qvac/sdk 0.1.0-dev.1760648187.328e967
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +301 -0
- package/dist/client/api/cancel.d.ts +25 -0
- package/dist/client/api/cancel.js +37 -0
- package/dist/client/api/completion-stream.d.ts +50 -0
- package/dist/client/api/completion-stream.js +103 -0
- package/dist/client/api/download-asset.d.ts +39 -0
- package/dist/client/api/download-asset.js +72 -0
- package/dist/client/api/embed.d.ts +11 -0
- package/dist/client/api/embed.js +24 -0
- package/dist/client/api/index.d.ts +13 -0
- package/dist/client/api/index.js +12 -0
- package/dist/client/api/load-model.d.ts +98 -0
- package/dist/client/api/load-model.js +154 -0
- package/dist/client/api/logging-stream.d.ts +21 -0
- package/dist/client/api/logging-stream.js +32 -0
- package/dist/client/api/ping.d.ts +11 -0
- package/dist/client/api/ping.js +18 -0
- package/dist/client/api/provide.d.ts +18 -0
- package/dist/client/api/provide.js +27 -0
- package/dist/client/api/rag.d.ts +42 -0
- package/dist/client/api/rag.js +97 -0
- package/dist/client/api/transcribe.d.ts +24 -0
- package/dist/client/api/transcribe.js +52 -0
- package/dist/client/api/translate.d.ts +47 -0
- package/dist/client/api/translate.js +114 -0
- package/dist/client/api/unload-model.d.ts +11 -0
- package/dist/client/api/unload-model.js +26 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +1 -0
- package/dist/client/logging-stream-registry.d.ts +5 -0
- package/dist/client/logging-stream-registry.js +60 -0
- package/dist/client/rpc/bare-client.d.ts +112 -0
- package/dist/client/rpc/bare-client.js +82 -0
- package/dist/client/rpc/bare-rpc-client.d.ts +4 -0
- package/dist/client/rpc/bare-rpc-client.js +87 -0
- package/dist/client/rpc/expo-rpc-client.d.ts +3 -0
- package/dist/client/rpc/expo-rpc-client.js +57 -0
- package/dist/client/rpc/node-rpc-client.d.ts +9 -0
- package/dist/client/rpc/node-rpc-client.js +99 -0
- package/dist/client/rpc/rpc-client.d.ts +5 -0
- package/dist/client/rpc/rpc-client.js +91 -0
- package/dist/client/rpc/rpc-error.d.ts +19 -0
- package/dist/client/rpc/rpc-error.js +39 -0
- package/dist/constants/audio.d.ts +3 -0
- package/dist/constants/audio.js +17 -0
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.js +1 -0
- package/dist/examples/delegated-inference/consumer.d.ts +2 -0
- package/dist/examples/delegated-inference/consumer.js +56 -0
- package/dist/examples/delegated-inference/provider.d.ts +2 -0
- package/dist/examples/delegated-inference/provider.js +57 -0
- package/dist/examples/download-with-cancel.d.ts +2 -0
- package/dist/examples/download-with-cancel.js +46 -0
- package/dist/examples/embed-hyperdrive.d.ts +2 -0
- package/dist/examples/embed-hyperdrive.js +19 -0
- package/dist/examples/kv-cache-example.d.ts +2 -0
- package/dist/examples/kv-cache-example.js +74 -0
- package/dist/examples/llamacpp-file-logging.d.ts +2 -0
- package/dist/examples/llamacpp-file-logging.js +62 -0
- package/dist/examples/llamacpp-filesystem.d.ts +2 -0
- package/dist/examples/llamacpp-filesystem.js +40 -0
- package/dist/examples/llamacpp-http.d.ts +2 -0
- package/dist/examples/llamacpp-http.js +41 -0
- package/dist/examples/llamacpp-hyperdrive.d.ts +2 -0
- package/dist/examples/llamacpp-hyperdrive.js +39 -0
- package/dist/examples/llamacpp-multimodal.d.ts +2 -0
- package/dist/examples/llamacpp-multimodal.js +62 -0
- package/dist/examples/llamacpp-native-tools.d.ts +2 -0
- package/dist/examples/llamacpp-native-tools.js +64 -0
- package/dist/examples/llamacpp-tools-routing.d.ts +2 -0
- package/dist/examples/llamacpp-tools-routing.js +364 -0
- package/dist/examples/llamacpp-tools.d.ts +2 -0
- package/dist/examples/llamacpp-tools.js +81 -0
- package/dist/examples/multi-model-demo.d.ts +2 -0
- package/dist/examples/multi-model-demo.js +75 -0
- package/dist/examples/parallel-download.d.ts +2 -0
- package/dist/examples/parallel-download.js +21 -0
- package/dist/examples/rag/rag-chromadb.d.ts +2 -0
- package/dist/examples/rag/rag-chromadb.js +130 -0
- package/dist/examples/rag/rag-hyperdb-workspaces.d.ts +2 -0
- package/dist/examples/rag/rag-hyperdb-workspaces.js +106 -0
- package/dist/examples/rag/rag-hyperdb.d.ts +2 -0
- package/dist/examples/rag/rag-hyperdb.js +50 -0
- package/dist/examples/rag/rag-lancedb.d.ts +2 -0
- package/dist/examples/rag/rag-lancedb.js +95 -0
- package/dist/examples/rag/rag-sqlite.d.ts +2 -0
- package/dist/examples/rag/rag-sqlite.js +107 -0
- package/dist/examples/seed-hyperdrive.d.ts +2 -0
- package/dist/examples/seed-hyperdrive.js +21 -0
- package/dist/examples/translation/translation-indic.d.ts +2 -0
- package/dist/examples/translation/translation-indic.js +30 -0
- package/dist/examples/translation/translation-llm-context.d.ts +2 -0
- package/dist/examples/translation/translation-llm-context.js +30 -0
- package/dist/examples/translation/translation-llm.d.ts +2 -0
- package/dist/examples/translation/translation-llm.js +38 -0
- package/dist/examples/translation/translation-opus.d.ts +2 -0
- package/dist/examples/translation/translation-opus.js +30 -0
- package/dist/examples/translation/translation-stream.d.ts +2 -0
- package/dist/examples/translation/translation-stream.js +35 -0
- package/dist/examples/whispercpp-filesystem.d.ts +2 -0
- package/dist/examples/whispercpp-filesystem.js +43 -0
- package/dist/examples/whispercpp-microphone-record.d.ts +2 -0
- package/dist/examples/whispercpp-microphone-record.js +311 -0
- package/dist/expo/plugins/index.d.ts +5 -0
- package/dist/expo/plugins/index.js +5 -0
- package/dist/expo/plugins/withMobileBundle.d.ts +8 -0
- package/dist/expo/plugins/withMobileBundle.js +60 -0
- package/dist/expo/plugins/withOpenCL.d.ts +9 -0
- package/dist/expo/plugins/withOpenCL.js +118 -0
- package/dist/expo/plugins/withQvacSDK.d.ts +9 -0
- package/dist/expo/plugins/withQvacSDK.js +13 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/logging/base-logger.d.ts +7 -0
- package/dist/logging/base-logger.js +55 -0
- package/dist/logging/index.d.ts +4 -0
- package/dist/logging/index.js +2 -0
- package/dist/logging/logger.d.ts +5 -0
- package/dist/logging/logger.js +28 -0
- package/dist/logging/stream-logger.d.ts +3 -0
- package/dist/logging/stream-logger.js +9 -0
- package/dist/logging/transport.d.ts +3 -0
- package/dist/logging/transport.js +15 -0
- package/dist/logging/types.d.ts +18 -0
- package/dist/logging/types.js +1 -0
- package/dist/logging/utils.d.ts +4 -0
- package/dist/logging/utils.js +47 -0
- package/dist/models/hyperdrive/index.d.ts +2 -0
- package/dist/models/hyperdrive/index.js +2 -0
- package/dist/models/hyperdrive/models.d.ts +475 -0
- package/dist/models/hyperdrive/models.js +534 -0
- package/dist/schemas/cancel.d.ts +33 -0
- package/dist/schemas/cancel.js +25 -0
- package/dist/schemas/common.d.ts +626 -0
- package/dist/schemas/common.js +47 -0
- package/dist/schemas/completion-stream.d.ts +125 -0
- package/dist/schemas/completion-stream.js +53 -0
- package/dist/schemas/delegate.d.ts +9 -0
- package/dist/schemas/delegate.js +9 -0
- package/dist/schemas/download-asset.d.ts +75 -0
- package/dist/schemas/download-asset.js +43 -0
- package/dist/schemas/embed.d.ts +20 -0
- package/dist/schemas/embed.js +14 -0
- package/dist/schemas/error.d.ts +13 -0
- package/dist/schemas/error.js +35 -0
- package/dist/schemas/index.d.ts +19 -0
- package/dist/schemas/index.js +19 -0
- package/dist/schemas/llamacpp-config.d.ts +30 -0
- package/dist/schemas/llamacpp-config.js +39 -0
- package/dist/schemas/load-model.d.ts +1259 -0
- package/dist/schemas/load-model.js +108 -0
- package/dist/schemas/logging-stream.d.ts +27 -0
- package/dist/schemas/logging-stream.js +16 -0
- package/dist/schemas/ping.d.ts +11 -0
- package/dist/schemas/ping.js +8 -0
- package/dist/schemas/provide.d.ts +43 -0
- package/dist/schemas/provide.js +25 -0
- package/dist/schemas/rag.d.ts +159 -0
- package/dist/schemas/rag.js +78 -0
- package/dist/schemas/transcription.d.ts +24 -0
- package/dist/schemas/transcription.js +15 -0
- package/dist/schemas/translate.d.ts +82 -0
- package/dist/schemas/translate.js +42 -0
- package/dist/schemas/translation-config.d.ts +83 -0
- package/dist/schemas/translation-config.js +46 -0
- package/dist/schemas/unload-model.d.ts +19 -0
- package/dist/schemas/unload-model.js +13 -0
- package/dist/schemas/whispercpp-config.d.ts +25 -0
- package/dist/schemas/whispercpp-config.js +18 -0
- package/dist/server/bare/addons/cancel.d.ts +3 -0
- package/dist/server/bare/addons/cancel.js +12 -0
- package/dist/server/bare/addons/index.d.ts +4 -0
- package/dist/server/bare/addons/index.js +3 -0
- package/dist/server/bare/addons/llamacpp/create-model.d.ts +5 -0
- package/dist/server/bare/addons/llamacpp/create-model.js +57 -0
- package/dist/server/bare/addons/llamacpp/handlers/completion-stream.d.ts +3 -0
- package/dist/server/bare/addons/llamacpp/handlers/completion-stream.js +65 -0
- package/dist/server/bare/addons/llamacpp/handlers/embed.d.ts +4 -0
- package/dist/server/bare/addons/llamacpp/handlers/embed.js +40 -0
- package/dist/server/bare/addons/llamacpp/index.d.ts +4 -0
- package/dist/server/bare/addons/llamacpp/index.js +3 -0
- package/dist/server/bare/addons/llamacpp/kv-cache-utils.d.ts +19 -0
- package/dist/server/bare/addons/llamacpp/kv-cache-utils.js +46 -0
- package/dist/server/bare/addons/load-model.d.ts +3 -0
- package/dist/server/bare/addons/load-model.js +55 -0
- package/dist/server/bare/addons/translation/create-model.d.ts +4 -0
- package/dist/server/bare/addons/translation/create-model.js +45 -0
- package/dist/server/bare/addons/translation/handlers/translate.d.ts +3 -0
- package/dist/server/bare/addons/translation/handlers/translate.js +86 -0
- package/dist/server/bare/addons/translation/index.d.ts +3 -0
- package/dist/server/bare/addons/translation/index.js +2 -0
- package/dist/server/bare/addons/unload-model.d.ts +3 -0
- package/dist/server/bare/addons/unload-model.js +20 -0
- package/dist/server/bare/addons/whispercpp/create-model.d.ts +6 -0
- package/dist/server/bare/addons/whispercpp/create-model.js +55 -0
- package/dist/server/bare/addons/whispercpp/handlers/transcribe-stream.d.ts +3 -0
- package/dist/server/bare/addons/whispercpp/handlers/transcribe-stream.js +42 -0
- package/dist/server/bare/addons/whispercpp/index.d.ts +3 -0
- package/dist/server/bare/addons/whispercpp/index.js +2 -0
- package/dist/server/bare/delegate-rpc-client.d.ts +4 -0
- package/dist/server/bare/delegate-rpc-client.js +70 -0
- package/dist/server/bare/hyperswarm.d.ts +7 -0
- package/dist/server/bare/hyperswarm.js +62 -0
- package/dist/server/bare/rag-hyperdb/handlers/delete-embeddings.d.ts +3 -0
- package/dist/server/bare/rag-hyperdb/handlers/delete-embeddings.js +12 -0
- package/dist/server/bare/rag-hyperdb/handlers/save-embeddings.d.ts +6 -0
- package/dist/server/bare/rag-hyperdb/handlers/save-embeddings.js +16 -0
- package/dist/server/bare/rag-hyperdb/handlers/search.d.ts +3 -0
- package/dist/server/bare/rag-hyperdb/handlers/search.js +15 -0
- package/dist/server/bare/rag-hyperdb/index.d.ts +5 -0
- package/dist/server/bare/rag-hyperdb/index.js +4 -0
- package/dist/server/bare/rag-hyperdb/rag-manager.d.ts +5 -0
- package/dist/server/bare/rag-hyperdb/rag-manager.js +61 -0
- package/dist/server/bare/registry/logging-stream-registry.d.ts +12 -0
- package/dist/server/bare/registry/logging-stream-registry.js +46 -0
- package/dist/server/bare/registry/model-registry.d.ts +64 -0
- package/dist/server/bare/registry/model-registry.js +95 -0
- package/dist/server/error-handlers.d.ts +4 -0
- package/dist/server/error-handlers.js +27 -0
- package/dist/server/http-server.d.ts +2 -0
- package/dist/server/http-server.js +189 -0
- package/dist/server/rpc/create-server.d.ts +4 -0
- package/dist/server/rpc/create-server.js +19 -0
- package/dist/server/rpc/handle-request.d.ts +12 -0
- package/dist/server/rpc/handle-request.js +220 -0
- package/dist/server/rpc/handlers/cancelHandler.d.ts +3 -0
- package/dist/server/rpc/handlers/cancelHandler.js +27 -0
- package/dist/server/rpc/handlers/completion-stream-delegated.d.ts +3 -0
- package/dist/server/rpc/handlers/completion-stream-delegated.js +30 -0
- package/dist/server/rpc/handlers/completion-stream.d.ts +3 -0
- package/dist/server/rpc/handlers/completion-stream.js +52 -0
- package/dist/server/rpc/handlers/download-asset.d.ts +3 -0
- package/dist/server/rpc/handlers/download-asset.js +21 -0
- package/dist/server/rpc/handlers/embed.d.ts +3 -0
- package/dist/server/rpc/handlers/embed.js +21 -0
- package/dist/server/rpc/handlers/index.d.ts +23 -0
- package/dist/server/rpc/handlers/index.js +22 -0
- package/dist/server/rpc/handlers/load-model/download-manager.d.ts +31 -0
- package/dist/server/rpc/handlers/load-model/download-manager.js +88 -0
- package/dist/server/rpc/handlers/load-model/http.d.ts +3 -0
- package/dist/server/rpc/handlers/load-model/http.js +337 -0
- package/dist/server/rpc/handlers/load-model/hyperdrive.d.ts +4 -0
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +332 -0
- package/dist/server/rpc/handlers/load-model/index.d.ts +4 -0
- package/dist/server/rpc/handlers/load-model/index.js +3 -0
- package/dist/server/rpc/handlers/load-model/resolve.d.ts +3 -0
- package/dist/server/rpc/handlers/load-model/resolve.js +121 -0
- package/dist/server/rpc/handlers/load-model-delegated.d.ts +3 -0
- package/dist/server/rpc/handlers/load-model-delegated.js +93 -0
- package/dist/server/rpc/handlers/load-model.d.ts +3 -0
- package/dist/server/rpc/handlers/load-model.js +41 -0
- package/dist/server/rpc/handlers/logging-stream.d.ts +3 -0
- package/dist/server/rpc/handlers/logging-stream.js +37 -0
- package/dist/server/rpc/handlers/provideHandler/connection.d.ts +3 -0
- package/dist/server/rpc/handlers/provideHandler/connection.js +25 -0
- package/dist/server/rpc/handlers/provideHandler/handler.d.ts +3 -0
- package/dist/server/rpc/handlers/provideHandler/handler.js +50 -0
- package/dist/server/rpc/handlers/provideHandler/proxy.d.ts +3 -0
- package/dist/server/rpc/handlers/provideHandler/proxy.js +22 -0
- package/dist/server/rpc/handlers/provideHandler.d.ts +2 -0
- package/dist/server/rpc/handlers/provideHandler.js +2 -0
- package/dist/server/rpc/handlers/rag.d.ts +3 -0
- package/dist/server/rpc/handlers/rag.js +67 -0
- package/dist/server/rpc/handlers/transcribe-stream.d.ts +3 -0
- package/dist/server/rpc/handlers/transcribe-stream.js +26 -0
- package/dist/server/rpc/handlers/translate.d.ts +3 -0
- package/dist/server/rpc/handlers/translate.js +51 -0
- package/dist/server/rpc/handlers/unload-model.d.ts +3 -0
- package/dist/server/rpc/handlers/unload-model.js +20 -0
- package/dist/server/rpc/index.d.ts +3 -0
- package/dist/server/rpc/index.js +2 -0
- package/dist/server/utils/audio/decoder.d.ts +4 -0
- package/dist/server/utils/audio/decoder.js +41 -0
- package/dist/server/utils/cache.d.ts +15 -0
- package/dist/server/utils/cache.js +32 -0
- package/dist/server/utils/hash.d.ts +5 -0
- package/dist/server/utils/hash.js +11 -0
- package/dist/server/utils/index.d.ts +5 -0
- package/dist/server/utils/index.js +4 -0
- package/dist/server/utils/model-path.d.ts +5 -0
- package/dist/server/utils/model-path.js +7 -0
- package/dist/server/worker.d.ts +6 -0
- package/dist/server/worker.js +77 -0
- package/dist/utils/withTimeout.d.ts +11 -0
- package/dist/utils/withTimeout.js +37 -0
- package/package.json +129 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { completionStreamResponseSchema, } from "../../schemas/index.js";
|
|
2
|
+
import { stream as streamRpc } from "../rpc/rpc-client.js";
|
|
3
|
+
/**
|
|
4
|
+
* Generates completion from a language model based on conversation history.
|
|
5
|
+
*
|
|
6
|
+
* @param params - The completion parameters
|
|
7
|
+
* @param params.modelId - The identifier of the model to use for completion
|
|
8
|
+
* @param params.history - Array of conversation messages with role, content, and optional attachments
|
|
9
|
+
* @param params.stream - Whether to stream tokens (true) or return complete response (false). Defaults to true
|
|
10
|
+
* @param params.tools - Optional array of tools that can be used by the model
|
|
11
|
+
* @param params.kvCache - Optional boolean to enable KV cache for faster subsequent completions
|
|
12
|
+
* @returns Object with tokenStream generator, text promise, and stats promise
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Streaming mode
|
|
16
|
+
* const result = completion({
|
|
17
|
+
* modelId: "llama-2",
|
|
18
|
+
* history: [
|
|
19
|
+
* { role: "user", content: "Hello, how are you?" }
|
|
20
|
+
* ],
|
|
21
|
+
* stream: true,
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* for await (const token of result.tokenStream) {
|
|
25
|
+
* console.log(token);
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* const stats = await result.stats;
|
|
29
|
+
* console.log("Performance:", stats);
|
|
30
|
+
*
|
|
31
|
+
* // Non-streaming mode
|
|
32
|
+
* const response = completion({
|
|
33
|
+
* modelId: "llama-2",
|
|
34
|
+
* history: [
|
|
35
|
+
* { role: "user", content: "What is the capital of France?" }
|
|
36
|
+
* ],
|
|
37
|
+
* stream: false,
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* const text = await response.text;
|
|
41
|
+
* const stats = await response.stats;
|
|
42
|
+
* console.log(text);
|
|
43
|
+
* console.log(stats);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export function completion(params) {
|
|
47
|
+
const request = {
|
|
48
|
+
type: "completionStream",
|
|
49
|
+
...params,
|
|
50
|
+
stream: params.stream ?? true,
|
|
51
|
+
};
|
|
52
|
+
let stats;
|
|
53
|
+
let statsResolver = () => { };
|
|
54
|
+
const statsPromise = new Promise((resolve) => {
|
|
55
|
+
statsResolver = resolve;
|
|
56
|
+
});
|
|
57
|
+
if (params.stream) {
|
|
58
|
+
const tokenStream = (async function* () {
|
|
59
|
+
for await (const response of streamRpc(request)) {
|
|
60
|
+
if (response.type === "completionStream") {
|
|
61
|
+
const streamResponse = completionStreamResponseSchema.parse(response);
|
|
62
|
+
if (!streamResponse.done) {
|
|
63
|
+
yield streamResponse.token;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
stats = streamResponse.stats;
|
|
67
|
+
statsResolver(stats);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
})();
|
|
72
|
+
const textPromise = Promise.resolve("");
|
|
73
|
+
return {
|
|
74
|
+
tokenStream,
|
|
75
|
+
text: textPromise,
|
|
76
|
+
stats: statsPromise,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const tokenStream = (async function* () {
|
|
81
|
+
//Empty generator for non-streaming mode
|
|
82
|
+
})();
|
|
83
|
+
const textPromise = (async () => {
|
|
84
|
+
let buffer = "";
|
|
85
|
+
for await (const response of streamRpc(request)) {
|
|
86
|
+
if (response.type === "completionStream") {
|
|
87
|
+
const streamResponse = completionStreamResponseSchema.parse(response);
|
|
88
|
+
buffer += streamResponse.token;
|
|
89
|
+
if (streamResponse.done) {
|
|
90
|
+
stats = streamResponse.stats;
|
|
91
|
+
statsResolver(stats);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return buffer;
|
|
96
|
+
})();
|
|
97
|
+
return {
|
|
98
|
+
tokenStream,
|
|
99
|
+
text: textPromise,
|
|
100
|
+
stats: statsPromise,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type DownloadAssetOptions as BaseDownloadAssetOptions } from "../../schemas/index";
|
|
2
|
+
export type DownloadAssetOptions = BaseDownloadAssetOptions;
|
|
3
|
+
/**
|
|
4
|
+
* Downloads an asset (model file) without loading it into memory.
|
|
5
|
+
*
|
|
6
|
+
* This function is specifically designed for download-only operations and
|
|
7
|
+
* doesn't accept runtime configuration options like modelConfig or delegate.
|
|
8
|
+
* Use this for download-only operations instead of loadModel for better semantic clarity.
|
|
9
|
+
*
|
|
10
|
+
* @param options - Download configuration including:
|
|
11
|
+
* - assetSrc: The location from which the asset is downloaded (local path, remote URL, or Hyperdrive URL)
|
|
12
|
+
* - seed: Optional boolean for hyperdrive seeding
|
|
13
|
+
* - onProgress: Optional callback for download progress
|
|
14
|
+
*
|
|
15
|
+
* @returns Promise that resolves to the asset ID (either the provided assetSrc or a generated ID)
|
|
16
|
+
*
|
|
17
|
+
* @throws {Error} When asset download fails, with details in the error message
|
|
18
|
+
* @throws {Error} When streaming ends unexpectedly (only when using onProgress)
|
|
19
|
+
* @throws {Error} When receiving an invalid response type from the server
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // Download model without loading
|
|
24
|
+
* const assetId = await downloadAsset({
|
|
25
|
+
* assetSrc: "/path/to/model.gguf",
|
|
26
|
+
* seed: true
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Download with progress tracking
|
|
30
|
+
* const assetId = await downloadAsset({
|
|
31
|
+
* assetSrc: "pear://key123/model.gguf",
|
|
32
|
+
* onProgress: (progress) => {
|
|
33
|
+
* console.log(`Downloaded: ${progress.percentage}%`);
|
|
34
|
+
* }
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function downloadAsset(options: DownloadAssetOptions): Promise<string>;
|
|
39
|
+
//# sourceMappingURL=download-asset.d.ts.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { send, stream } from "../rpc/rpc-client.js";
|
|
2
|
+
import { downloadAssetRequestSchema, } from "../../schemas/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Downloads an asset (model file) without loading it into memory.
|
|
5
|
+
*
|
|
6
|
+
* This function is specifically designed for download-only operations and
|
|
7
|
+
* doesn't accept runtime configuration options like modelConfig or delegate.
|
|
8
|
+
* Use this for download-only operations instead of loadModel for better semantic clarity.
|
|
9
|
+
*
|
|
10
|
+
* @param options - Download configuration including:
|
|
11
|
+
* - assetSrc: The location from which the asset is downloaded (local path, remote URL, or Hyperdrive URL)
|
|
12
|
+
* - seed: Optional boolean for hyperdrive seeding
|
|
13
|
+
* - onProgress: Optional callback for download progress
|
|
14
|
+
*
|
|
15
|
+
* @returns Promise that resolves to the asset ID (either the provided assetSrc or a generated ID)
|
|
16
|
+
*
|
|
17
|
+
* @throws {Error} When asset download fails, with details in the error message
|
|
18
|
+
* @throws {Error} When streaming ends unexpectedly (only when using onProgress)
|
|
19
|
+
* @throws {Error} When receiving an invalid response type from the server
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // Download model without loading
|
|
24
|
+
* const assetId = await downloadAsset({
|
|
25
|
+
* assetSrc: "/path/to/model.gguf",
|
|
26
|
+
* seed: true
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Download with progress tracking
|
|
30
|
+
* const assetId = await downloadAsset({
|
|
31
|
+
* assetSrc: "pear://key123/model.gguf",
|
|
32
|
+
* onProgress: (progress) => {
|
|
33
|
+
* console.log(`Downloaded: ${progress.percentage}%`);
|
|
34
|
+
* }
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export async function downloadAsset(options) {
|
|
39
|
+
const { assetSrc } = options;
|
|
40
|
+
const request = downloadAssetRequestSchema.parse({
|
|
41
|
+
type: "downloadAsset",
|
|
42
|
+
assetSrc: assetSrc,
|
|
43
|
+
withProgress: !!options.onProgress,
|
|
44
|
+
seed: options.seed,
|
|
45
|
+
});
|
|
46
|
+
if (options.onProgress) {
|
|
47
|
+
// Use streaming for progress updates
|
|
48
|
+
for await (const response of stream(request)) {
|
|
49
|
+
if (response.type === "modelProgress") {
|
|
50
|
+
options.onProgress(response);
|
|
51
|
+
}
|
|
52
|
+
else if (response.type === "downloadAsset") {
|
|
53
|
+
if (!response.success) {
|
|
54
|
+
throw new Error(response.error ?? "Failed to download asset");
|
|
55
|
+
}
|
|
56
|
+
return response.assetId ?? assetSrc;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
throw new Error("Stream ended without final response");
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// Use regular send for simple downloading
|
|
63
|
+
const response = await send(request);
|
|
64
|
+
if (response.type !== "downloadAsset") {
|
|
65
|
+
throw new Error("Invalid response type");
|
|
66
|
+
}
|
|
67
|
+
if (!response.success) {
|
|
68
|
+
throw new Error(response.error ?? "Failed to download asset");
|
|
69
|
+
}
|
|
70
|
+
return response.assetId ?? assetSrc;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type EmbedParams } from "../../schemas/index";
|
|
2
|
+
/**
|
|
3
|
+
* Generates embeddings for a given text using a specified model.
|
|
4
|
+
*
|
|
5
|
+
* @param params - The parameters for the embedding
|
|
6
|
+
* @param params.modelId - The identifier of the embedding model to use
|
|
7
|
+
* @param params.text - The input text to embed
|
|
8
|
+
* @throws {Error} When the response type is invalid or when the embedding fails
|
|
9
|
+
*/
|
|
10
|
+
export declare function embed(params: EmbedParams): Promise<number[]>;
|
|
11
|
+
//# sourceMappingURL=embed.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { send } from "../rpc/rpc-client.js";
|
|
2
|
+
import {} from "../../schemas/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Generates embeddings for a given text using a specified model.
|
|
5
|
+
*
|
|
6
|
+
* @param params - The parameters for the embedding
|
|
7
|
+
* @param params.modelId - The identifier of the embedding model to use
|
|
8
|
+
* @param params.text - The input text to embed
|
|
9
|
+
* @throws {Error} When the response type is invalid or when the embedding fails
|
|
10
|
+
*/
|
|
11
|
+
export async function embed(params) {
|
|
12
|
+
const request = {
|
|
13
|
+
type: "embed",
|
|
14
|
+
...params,
|
|
15
|
+
};
|
|
16
|
+
const response = await send(request);
|
|
17
|
+
if (response.type !== "embed") {
|
|
18
|
+
throw new Error("Invalid response type");
|
|
19
|
+
}
|
|
20
|
+
if (!response.success) {
|
|
21
|
+
throw new Error(response.error ?? "Failed to embed");
|
|
22
|
+
}
|
|
23
|
+
return response.embedding;
|
|
24
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { loadModel } from "./load-model";
|
|
2
|
+
export { downloadAsset } from "./download-asset";
|
|
3
|
+
export { completion } from "./completion-stream";
|
|
4
|
+
export { unloadModel } from "./unload-model";
|
|
5
|
+
export { loggingStream } from "./logging-stream";
|
|
6
|
+
export { ping } from "./ping";
|
|
7
|
+
export { transcribe, transcribeStream } from "./transcribe";
|
|
8
|
+
export { embed } from "./embed";
|
|
9
|
+
export { translate } from "./translate";
|
|
10
|
+
export { cancel } from "./cancel";
|
|
11
|
+
export { startQVACProvider } from "./provide";
|
|
12
|
+
export { ragSaveEmbeddings, ragSearch, ragDeleteEmbeddings } from "./rag";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { loadModel } from "./load-model.js";
|
|
2
|
+
export { downloadAsset } from "./download-asset.js";
|
|
3
|
+
export { completion } from "./completion-stream.js";
|
|
4
|
+
export { unloadModel } from "./unload-model.js";
|
|
5
|
+
export { loggingStream } from "./logging-stream.js";
|
|
6
|
+
export { ping } from "./ping.js";
|
|
7
|
+
export { transcribe, transcribeStream } from "./transcribe.js";
|
|
8
|
+
export { embed } from "./embed.js";
|
|
9
|
+
export { translate } from "./translate.js";
|
|
10
|
+
export { cancel } from "./cancel.js";
|
|
11
|
+
export { startQVACProvider } from "./provide.js";
|
|
12
|
+
export { ragSaveEmbeddings, ragSearch, ragDeleteEmbeddings } from "./rag.js";
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { type Logger } from "../../logging/index";
|
|
2
|
+
import { type LoadModelOptions as BaseLoadModelOptions } from "../../schemas/index";
|
|
3
|
+
export type LoadModelOptions = BaseLoadModelOptions & {
|
|
4
|
+
logger?: Logger;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Loads a machine learning model from a local path, remote URL, or Hyperdrive key.
|
|
8
|
+
*
|
|
9
|
+
* This function supports three model types: LLM (Large Language Model), Whisper (speech recognition),
|
|
10
|
+
* and embeddings. It can handle both local file paths and Hyperdrive URLs (pear://).
|
|
11
|
+
*
|
|
12
|
+
* When `onProgress` is provided, the function uses streaming to provide real-time download progress.
|
|
13
|
+
* Otherwise, it uses a simple request-response pattern for faster execution.
|
|
14
|
+
*
|
|
15
|
+
* @param options - An object that defines all configuration parameters required for loading the model, including:
|
|
16
|
+
* - modelSrc: The location from which the model weights are fetched (local path, remote URL, or Hyperdrive URL)
|
|
17
|
+
* - modelType: The type of model ("llm", "whisper", "embeddings", or "nmt")
|
|
18
|
+
* - modelConfig: Model-specific configuration options
|
|
19
|
+
* - projectionModelSrc: (LLM only) Projection model source for multimodal models
|
|
20
|
+
* - vadModelSrc: (Whisper only) VAD model source for voice activity detection
|
|
21
|
+
*
|
|
22
|
+
* @returns Promise that resolves to the model ID (either the provided modelSrc or a generated ID)
|
|
23
|
+
*
|
|
24
|
+
* @throws {Error} When model loading fails, with details in the error message
|
|
25
|
+
* @throws {Error} When streaming ends unexpectedly (only when using onProgress)
|
|
26
|
+
* @throws {Error} When receiving an invalid response type from the server
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* // Local file path - absolute path
|
|
31
|
+
* const localModelId = await loadModel({
|
|
32
|
+
* modelSrc: "/home/user/models/llama-7b.gguf",
|
|
33
|
+
* modelType: "llm",
|
|
34
|
+
* modelConfig: { contextSize: 2048 }
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // Local file path - relative path
|
|
38
|
+
* const relativeModelId = await loadModel({
|
|
39
|
+
* modelSrc: "./models/whisper-base.gguf",
|
|
40
|
+
* modelType: "whisper"
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // Hyperdrive URL with key and path
|
|
44
|
+
* const hyperdriveId = await loadModel({
|
|
45
|
+
* modelSrc: "pear://<hyperdrive-key>/llama-7b.gguf",
|
|
46
|
+
* modelType: "llm",
|
|
47
|
+
* modelConfig: { contextSize: 2048 }
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* // Remote HTTP/HTTPS URL with progress tracking
|
|
51
|
+
* const remoteId = await loadModel({
|
|
52
|
+
* modelSrc: "https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/main/llama-2-7b-chat.Q4_K_M.gguf",
|
|
53
|
+
* modelType: "llm",
|
|
54
|
+
* onProgress: (progress) => {
|
|
55
|
+
* console.log(`Downloaded: ${progress.percentage}%`);
|
|
56
|
+
* }
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* // Multimodal model with projection
|
|
60
|
+
* const multimodalId = await loadModel({
|
|
61
|
+
* modelSrc: "https://huggingface.co/.../main-model.gguf",
|
|
62
|
+
* modelType: "llm",
|
|
63
|
+
* projectionModelSrc: "https://huggingface.co/.../projection-model.gguf",
|
|
64
|
+
* modelConfig: { ctx_size: 512 },
|
|
65
|
+
* onProgress: (progress) => {
|
|
66
|
+
* console.log(`Loading: ${progress.percentage}%`);
|
|
67
|
+
* }
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* // Whisper with VAD model
|
|
71
|
+
* const whisperId = await loadModel({
|
|
72
|
+
* modelSrc: "https://huggingface.co/.../whisper-model.gguf",
|
|
73
|
+
* modelType: "whisper",
|
|
74
|
+
* vadModelSrc: "https://huggingface.co/.../vad-model.bin",
|
|
75
|
+
* modelConfig: {
|
|
76
|
+
* mode: "caption",
|
|
77
|
+
* output_format: "plaintext",
|
|
78
|
+
* min_seconds: 2,
|
|
79
|
+
* max_seconds: 6
|
|
80
|
+
* }
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* // Load with automatic logging - logs from the model will be forwarded to your logger
|
|
84
|
+
* import { getLogger } from "../../logging/index";
|
|
85
|
+
* const logger = getLogger("my-app");
|
|
86
|
+
*
|
|
87
|
+
* const modelId = await loadModel({
|
|
88
|
+
* modelSrc: "/path/to/model.gguf",
|
|
89
|
+
* modelType: "llm",
|
|
90
|
+
* logger // Pass logger in options
|
|
91
|
+
* });
|
|
92
|
+
*
|
|
93
|
+
* // Now any logs from the model operations will appear in your logger automatically
|
|
94
|
+
* // No need to manually manage logging streams!
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function loadModel(options: LoadModelOptions): Promise<string>;
|
|
98
|
+
//# sourceMappingURL=load-model.d.ts.map
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { send, stream } from "../rpc/rpc-client.js";
|
|
2
|
+
import {} from "../../logging/index.js";
|
|
3
|
+
import { startLoggingStreamForModel } from "../logging-stream-registry.js";
|
|
4
|
+
import { loadModelRequestSchema, } from "../../schemas/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Loads a machine learning model from a local path, remote URL, or Hyperdrive key.
|
|
7
|
+
*
|
|
8
|
+
* This function supports three model types: LLM (Large Language Model), Whisper (speech recognition),
|
|
9
|
+
* and embeddings. It can handle both local file paths and Hyperdrive URLs (pear://).
|
|
10
|
+
*
|
|
11
|
+
* When `onProgress` is provided, the function uses streaming to provide real-time download progress.
|
|
12
|
+
* Otherwise, it uses a simple request-response pattern for faster execution.
|
|
13
|
+
*
|
|
14
|
+
* @param options - An object that defines all configuration parameters required for loading the model, including:
|
|
15
|
+
* - modelSrc: The location from which the model weights are fetched (local path, remote URL, or Hyperdrive URL)
|
|
16
|
+
* - modelType: The type of model ("llm", "whisper", "embeddings", or "nmt")
|
|
17
|
+
* - modelConfig: Model-specific configuration options
|
|
18
|
+
* - projectionModelSrc: (LLM only) Projection model source for multimodal models
|
|
19
|
+
* - vadModelSrc: (Whisper only) VAD model source for voice activity detection
|
|
20
|
+
*
|
|
21
|
+
* @returns Promise that resolves to the model ID (either the provided modelSrc or a generated ID)
|
|
22
|
+
*
|
|
23
|
+
* @throws {Error} When model loading fails, with details in the error message
|
|
24
|
+
* @throws {Error} When streaming ends unexpectedly (only when using onProgress)
|
|
25
|
+
* @throws {Error} When receiving an invalid response type from the server
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // Local file path - absolute path
|
|
30
|
+
* const localModelId = await loadModel({
|
|
31
|
+
* modelSrc: "/home/user/models/llama-7b.gguf",
|
|
32
|
+
* modelType: "llm",
|
|
33
|
+
* modelConfig: { contextSize: 2048 }
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* // Local file path - relative path
|
|
37
|
+
* const relativeModelId = await loadModel({
|
|
38
|
+
* modelSrc: "./models/whisper-base.gguf",
|
|
39
|
+
* modelType: "whisper"
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* // Hyperdrive URL with key and path
|
|
43
|
+
* const hyperdriveId = await loadModel({
|
|
44
|
+
* modelSrc: "pear://<hyperdrive-key>/llama-7b.gguf",
|
|
45
|
+
* modelType: "llm",
|
|
46
|
+
* modelConfig: { contextSize: 2048 }
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* // Remote HTTP/HTTPS URL with progress tracking
|
|
50
|
+
* const remoteId = await loadModel({
|
|
51
|
+
* modelSrc: "https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/main/llama-2-7b-chat.Q4_K_M.gguf",
|
|
52
|
+
* modelType: "llm",
|
|
53
|
+
* onProgress: (progress) => {
|
|
54
|
+
* console.log(`Downloaded: ${progress.percentage}%`);
|
|
55
|
+
* }
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* // Multimodal model with projection
|
|
59
|
+
* const multimodalId = await loadModel({
|
|
60
|
+
* modelSrc: "https://huggingface.co/.../main-model.gguf",
|
|
61
|
+
* modelType: "llm",
|
|
62
|
+
* projectionModelSrc: "https://huggingface.co/.../projection-model.gguf",
|
|
63
|
+
* modelConfig: { ctx_size: 512 },
|
|
64
|
+
* onProgress: (progress) => {
|
|
65
|
+
* console.log(`Loading: ${progress.percentage}%`);
|
|
66
|
+
* }
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* // Whisper with VAD model
|
|
70
|
+
* const whisperId = await loadModel({
|
|
71
|
+
* modelSrc: "https://huggingface.co/.../whisper-model.gguf",
|
|
72
|
+
* modelType: "whisper",
|
|
73
|
+
* vadModelSrc: "https://huggingface.co/.../vad-model.bin",
|
|
74
|
+
* modelConfig: {
|
|
75
|
+
* mode: "caption",
|
|
76
|
+
* output_format: "plaintext",
|
|
77
|
+
* min_seconds: 2,
|
|
78
|
+
* max_seconds: 6
|
|
79
|
+
* }
|
|
80
|
+
* });
|
|
81
|
+
*
|
|
82
|
+
* // Load with automatic logging - logs from the model will be forwarded to your logger
|
|
83
|
+
* import { getLogger } from "../../logging/index.js";
|
|
84
|
+
* const logger = getLogger("my-app");
|
|
85
|
+
*
|
|
86
|
+
* const modelId = await loadModel({
|
|
87
|
+
* modelSrc: "/path/to/model.gguf",
|
|
88
|
+
* modelType: "llm",
|
|
89
|
+
* logger // Pass logger in options
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* // Now any logs from the model operations will appear in your logger automatically
|
|
93
|
+
* // No need to manually manage logging streams!
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export async function loadModel(options) {
|
|
97
|
+
const { logger, modelSrc } = options;
|
|
98
|
+
const request = loadModelRequestSchema.parse({
|
|
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
|
+
});
|
|
109
|
+
if (options.onProgress) {
|
|
110
|
+
// Use streaming for progress updates
|
|
111
|
+
for await (const response of stream(request)) {
|
|
112
|
+
if (response.type === "modelProgress") {
|
|
113
|
+
options.onProgress(response);
|
|
114
|
+
}
|
|
115
|
+
else if (response.type === "loadModel") {
|
|
116
|
+
if (!response.success) {
|
|
117
|
+
throw new Error(response.error ?? "Failed to load model");
|
|
118
|
+
}
|
|
119
|
+
const modelId = response.modelId ?? modelSrc;
|
|
120
|
+
// Start logging stream in the background if logger is provided, catch to avoid failing the entire loadModel operation
|
|
121
|
+
if (logger) {
|
|
122
|
+
try {
|
|
123
|
+
startLoggingStreamForModel(modelId, logger);
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
console.warn(`Failed to start logging stream for model ${modelId}:`, error);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return modelId;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
throw new Error("Stream ended without final response");
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
// Use regular send for simple loading
|
|
136
|
+
const response = await send(request);
|
|
137
|
+
if (response.type !== "loadModel") {
|
|
138
|
+
throw new Error("Invalid response type");
|
|
139
|
+
}
|
|
140
|
+
if (!response.success) {
|
|
141
|
+
throw new Error(response.error ?? "Failed to load model");
|
|
142
|
+
}
|
|
143
|
+
const modelId = response.modelId ?? modelSrc;
|
|
144
|
+
if (logger) {
|
|
145
|
+
try {
|
|
146
|
+
startLoggingStreamForModel(modelId, logger);
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
console.warn(`Failed to start logging stream for model ${modelId}:`, error);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return modelId;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { LoggingStreamResponse, LoggingParams } from "../../schemas/logging-stream";
|
|
2
|
+
/**
|
|
3
|
+
* Opens a logging stream for a specific model to receive real-time logs.
|
|
4
|
+
*
|
|
5
|
+
* @param params - The arguments for the logging stream
|
|
6
|
+
* @param params.modelId - The unique identifier of the model to stream logs for
|
|
7
|
+
* @returns AsyncGenerator yielding logging stream responses
|
|
8
|
+
* @throws {Error} When the response type is invalid or when the stream fails
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Open a logging stream for a model
|
|
13
|
+
* const logStream = loggingStream({ modelId: 'my-model-id' });
|
|
14
|
+
*
|
|
15
|
+
* for await (const logMessage of logStream) {
|
|
16
|
+
* console.log(`[${logMessage.level}] ${logMessage.namespace}: ${logMessage.message}`);
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function loggingStream(params: LoggingParams): AsyncGenerator<LoggingStreamResponse>;
|
|
21
|
+
//# sourceMappingURL=logging-stream.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { stream } from "../rpc/rpc-client.js";
|
|
2
|
+
/**
|
|
3
|
+
* Opens a logging stream for a specific model to receive real-time logs.
|
|
4
|
+
*
|
|
5
|
+
* @param params - The arguments for the logging stream
|
|
6
|
+
* @param params.modelId - The unique identifier of the model to stream logs for
|
|
7
|
+
* @returns AsyncGenerator yielding logging stream responses
|
|
8
|
+
* @throws {Error} When the response type is invalid or when the stream fails
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Open a logging stream for a model
|
|
13
|
+
* const logStream = loggingStream({ modelId: 'my-model-id' });
|
|
14
|
+
*
|
|
15
|
+
* for await (const logMessage of logStream) {
|
|
16
|
+
* console.log(`[${logMessage.level}] ${logMessage.namespace}: ${logMessage.message}`);
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export async function* loggingStream(params) {
|
|
21
|
+
const request = {
|
|
22
|
+
type: "loggingStream",
|
|
23
|
+
...params,
|
|
24
|
+
};
|
|
25
|
+
const responseStream = stream(request);
|
|
26
|
+
for await (const response of responseStream) {
|
|
27
|
+
if (response.type !== "loggingStream") {
|
|
28
|
+
throw new Error("Invalid response type");
|
|
29
|
+
}
|
|
30
|
+
yield response;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sends a ping request to the server and returns the pong response.
|
|
3
|
+
*
|
|
4
|
+
* @returns A promise that resolves to a pong response containing a number.
|
|
5
|
+
* @throws {Error} When the response type is not "pong".
|
|
6
|
+
*/
|
|
7
|
+
export declare function ping(): Promise<{
|
|
8
|
+
type: "pong";
|
|
9
|
+
number: number;
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=ping.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {} from "../../schemas/index.js";
|
|
2
|
+
import { send } from "../rpc/rpc-client.js";
|
|
3
|
+
/**
|
|
4
|
+
* Sends a ping request to the server and returns the pong response.
|
|
5
|
+
*
|
|
6
|
+
* @returns A promise that resolves to a pong response containing a number.
|
|
7
|
+
* @throws {Error} When the response type is not "pong".
|
|
8
|
+
*/
|
|
9
|
+
export async function ping() {
|
|
10
|
+
const request = {
|
|
11
|
+
type: "ping",
|
|
12
|
+
};
|
|
13
|
+
const response = await send(request);
|
|
14
|
+
if (response.type !== "pong") {
|
|
15
|
+
throw new Error("Invalid response type");
|
|
16
|
+
}
|
|
17
|
+
return response;
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ProvideParams } from "../../schemas/index";
|
|
2
|
+
/**
|
|
3
|
+
* Starts a provider service that offers QVAC capabilities to remote peers.
|
|
4
|
+
* The provider's keypair can be controlled via the seed option or QVAC_HYPERSWARM_SEED environment variable.
|
|
5
|
+
*
|
|
6
|
+
* @param options - Options object with required topic, optional seed, and optional firewall config
|
|
7
|
+
* @param options.topic - Topic hex string for peer discovery
|
|
8
|
+
* @param options.firewall - Optional firewall configuration to allow/deny specific public keys
|
|
9
|
+
* @returns A promise that resolves to the provide response containing success status and public key
|
|
10
|
+
* @throws {Error} When the response type is not "provide" or the request fails
|
|
11
|
+
*/
|
|
12
|
+
export declare function startQVACProvider(params: ProvideParams): Promise<{
|
|
13
|
+
type: "provide";
|
|
14
|
+
success: boolean;
|
|
15
|
+
error?: string | undefined;
|
|
16
|
+
publicKey?: string | undefined;
|
|
17
|
+
}>;
|
|
18
|
+
//# sourceMappingURL=provide.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {} from "../../schemas/index.js";
|
|
2
|
+
import { send } from "../rpc/rpc-client.js";
|
|
3
|
+
/**
|
|
4
|
+
* Starts a provider service that offers QVAC capabilities to remote peers.
|
|
5
|
+
* The provider's keypair can be controlled via the seed option or QVAC_HYPERSWARM_SEED environment variable.
|
|
6
|
+
*
|
|
7
|
+
* @param options - Options object with required topic, optional seed, and optional firewall config
|
|
8
|
+
* @param options.topic - Topic hex string for peer discovery
|
|
9
|
+
* @param options.firewall - Optional firewall configuration to allow/deny specific public keys
|
|
10
|
+
* @returns A promise that resolves to the provide response containing success status and public key
|
|
11
|
+
* @throws {Error} When the response type is not "provide" or the request fails
|
|
12
|
+
*/
|
|
13
|
+
export async function startQVACProvider(params) {
|
|
14
|
+
const request = {
|
|
15
|
+
type: "provide",
|
|
16
|
+
topic: params.topic,
|
|
17
|
+
firewall: params.firewall,
|
|
18
|
+
};
|
|
19
|
+
const response = await send(request);
|
|
20
|
+
if (response.type !== "provide") {
|
|
21
|
+
throw new Error("Invalid response type");
|
|
22
|
+
}
|
|
23
|
+
if (response.error) {
|
|
24
|
+
throw new Error(response.error);
|
|
25
|
+
}
|
|
26
|
+
return response;
|
|
27
|
+
}
|