@qvac/sdk 0.5.0 โ 0.6.1
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 +48 -11
- package/bare-imports.json +35 -0
- package/dist/client/api/cancel.d.ts +12 -3
- package/dist/client/api/cancel.js +12 -3
- package/dist/client/api/get-model-info.d.ts +2 -2
- package/dist/client/api/get-model-info.js +2 -2
- package/dist/client/api/index.d.ts +2 -1
- package/dist/client/api/index.js +2 -1
- package/dist/client/api/load-model.js +6 -1
- package/dist/client/api/ocr.d.ts +31 -0
- package/dist/client/api/ocr.js +88 -0
- package/dist/client/api/rag.d.ts +215 -20
- package/dist/client/api/rag.js +382 -23
- package/dist/client/api/translate.js +10 -11
- package/dist/client/api/unload-model.js +1 -1
- package/dist/client/init-hooks.d.ts +4 -3
- package/dist/client/init-hooks.js +40 -31
- package/dist/client/rpc/bare-client.d.ts +1 -178
- package/dist/client/rpc/bare-client.js +42 -9
- package/dist/client/rpc/expo-rpc-client.js +57 -2
- package/dist/client/rpc/node-rpc-client.js +5 -1
- package/dist/client/rpc/rpc-client.d.ts +1 -1
- package/dist/client/rpc/rpc-client.js +11 -57
- package/dist/examples/config/blind-relay/blind-relay.config.d.ts +5 -0
- package/dist/examples/config/blind-relay/blind-relay.config.js +7 -0
- package/dist/examples/config/default/default.config.d.ts +8 -0
- package/dist/examples/config/default/default.config.js +6 -0
- package/dist/examples/default-config-usage.d.ts +17 -0
- package/dist/examples/default-config-usage.js +47 -0
- package/dist/examples/delegated-inference/consumer.js +1 -0
- package/dist/examples/download-with-blind-relays.js +4 -3
- package/dist/examples/embed-hyperdrive.js +4 -0
- package/dist/examples/kv-cache-custom-key.js +16 -1
- package/dist/examples/llamacpp-sharded.js +12 -3
- package/dist/examples/ocr-fasttext.d.ts +2 -0
- package/dist/examples/ocr-fasttext.js +52 -0
- package/dist/examples/quickstart.d.ts +2 -0
- package/dist/examples/quickstart.js +28 -0
- package/dist/examples/rag/rag-hyperdb/cancellation.d.ts +2 -0
- package/dist/examples/rag/rag-hyperdb/cancellation.js +75 -0
- package/dist/examples/rag/rag-hyperdb/ingest.d.ts +2 -0
- package/dist/examples/rag/{rag-hyperdb.js โ rag-hyperdb/ingest.js} +10 -4
- package/dist/examples/rag/rag-hyperdb/pipeline.d.ts +2 -0
- package/dist/examples/rag/rag-hyperdb/pipeline.js +74 -0
- package/dist/examples/rag/rag-hyperdb/workspaces.d.ts +2 -0
- package/dist/examples/rag/rag-hyperdb/workspaces.js +178 -0
- package/dist/examples/translation/translation-bergamot-batch.d.ts +2 -0
- package/dist/examples/translation/translation-bergamot-batch.js +49 -0
- package/dist/examples/translation/translation-bergamot.d.ts +2 -0
- package/dist/examples/translation/translation-bergamot.js +39 -0
- package/dist/examples/translation/translation-indic.js +1 -0
- package/dist/examples/translation/translation-opus.js +1 -0
- package/dist/examples/translation/translation-stream.js +1 -0
- package/dist/expo/plugins/withMobileBundle.js +29 -10
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -1
- package/dist/logging/addon.js +23 -7
- package/dist/logging/base-logger.js +2 -2
- package/dist/logging/client-logger.js +15 -4
- package/dist/logging/index.d.ts +1 -0
- package/dist/logging/index.js +1 -0
- package/dist/logging/logger.js +11 -3
- package/dist/logging/namespaces.d.ts +1 -0
- package/dist/logging/namespaces.js +1 -0
- package/dist/logging/registry.d.ts +5 -0
- package/dist/logging/registry.js +17 -5
- package/dist/logging/transport.js +2 -2
- package/dist/logging/utils.d.ts +2 -0
- package/dist/logging/utils.js +62 -0
- package/dist/models/hyperdrive/models.d.ts +1096 -178
- package/dist/models/hyperdrive/models.js +1476 -507
- package/dist/schemas/archive.d.ts +9 -0
- package/dist/schemas/archive.js +17 -0
- package/dist/schemas/cancel.d.ts +6 -0
- package/dist/schemas/cancel.js +5 -0
- package/dist/schemas/common.d.ts +582 -77
- package/dist/schemas/common.js +6 -1
- package/dist/schemas/delegate.d.ts +1 -0
- package/dist/schemas/delegate.js +1 -0
- package/dist/schemas/download-asset.d.ts +21 -9
- package/dist/schemas/get-model-info.d.ts +12 -10
- package/dist/schemas/get-model-info.js +9 -1
- package/dist/schemas/index.d.ts +6 -2
- package/dist/schemas/index.js +9 -2
- package/dist/schemas/llamacpp-config.d.ts +112 -8
- package/dist/schemas/llamacpp-config.js +40 -8
- package/dist/schemas/load-model.d.ts +2993 -525
- package/dist/schemas/load-model.js +88 -33
- package/dist/schemas/logging-stream.d.ts +2 -2
- package/dist/schemas/model-src-utils.d.ts +38 -16
- package/dist/schemas/model-src-utils.js +4 -8
- package/dist/schemas/model-types.d.ts +154 -0
- package/dist/schemas/model-types.js +140 -0
- package/dist/schemas/ocr.d.ts +88 -0
- package/dist/schemas/ocr.js +52 -0
- package/dist/schemas/rag.d.ts +183 -52
- package/dist/schemas/rag.js +148 -23
- package/dist/schemas/reload-config.d.ts +20 -8
- package/dist/schemas/reload-config.js +7 -5
- package/dist/schemas/runtime-context.d.ts +19 -0
- package/dist/schemas/runtime-context.js +7 -0
- package/dist/schemas/sdk-config.d.ts +697 -2
- package/dist/schemas/sdk-config.js +99 -1
- package/dist/schemas/sdk-errors-client.d.ts +1 -0
- package/dist/schemas/sdk-errors-client.js +5 -0
- package/dist/schemas/sdk-errors-server.d.ts +14 -0
- package/dist/schemas/sdk-errors-server.js +70 -0
- package/dist/schemas/shard.d.ts +21 -0
- package/dist/schemas/shard.js +17 -0
- package/dist/schemas/translate.d.ts +68 -23
- package/dist/schemas/translate.js +37 -11
- package/dist/schemas/translation-config.d.ts +272 -29
- package/dist/schemas/translation-config.js +63 -6
- package/dist/scripts/run-unit-tests.d.ts +2 -0
- package/dist/scripts/run-unit-tests.js +17 -0
- package/dist/server/bare/addons/llamacpp-completion/cache-logger.d.ts +6 -0
- package/dist/server/bare/addons/llamacpp-completion/cache-logger.js +34 -0
- package/dist/server/bare/addons/{llamacpp โ llamacpp-completion}/create-model.d.ts +1 -5
- package/dist/server/bare/addons/{llamacpp โ llamacpp-completion}/create-model.js +3 -26
- package/dist/server/bare/addons/{llamacpp โ llamacpp-completion}/handlers/completion-stream.js +26 -7
- package/dist/server/bare/addons/llamacpp-completion/index.d.ts +4 -0
- package/dist/server/bare/addons/llamacpp-completion/index.js +3 -0
- package/dist/server/bare/addons/{llamacpp โ llamacpp-completion}/kv-cache-utils.d.ts +4 -1
- package/dist/server/bare/addons/{llamacpp โ llamacpp-completion}/kv-cache-utils.js +43 -10
- package/dist/server/bare/addons/llamacpp-embedding/create-model.d.ts +8 -0
- package/dist/server/bare/addons/llamacpp-embedding/create-model.js +38 -0
- package/dist/server/bare/addons/llamacpp-embedding/index.d.ts +3 -0
- package/dist/server/bare/addons/llamacpp-embedding/index.js +2 -0
- package/dist/server/bare/addons/load-model.js +28 -24
- package/dist/server/bare/addons/{translation โ nmtcpp-translation}/create-model.js +23 -8
- package/dist/server/bare/addons/{translation โ nmtcpp-translation}/handlers/translate.js +35 -11
- package/dist/server/bare/addons/onnx-ocr/create-model.d.ts +10 -0
- package/dist/server/bare/addons/onnx-ocr/create-model.js +39 -0
- package/dist/server/bare/addons/onnx-ocr/handlers/ocr-stream.d.ts +10 -0
- package/dist/server/bare/addons/onnx-ocr/handlers/ocr-stream.js +109 -0
- package/dist/server/bare/addons/onnx-ocr/index.d.ts +3 -0
- package/dist/server/bare/addons/onnx-ocr/index.js +2 -0
- package/dist/server/bare/addons/{whispercpp โ whispercpp-transcription}/create-model.js +2 -1
- package/dist/server/bare/delegate-rpc-client.js +19 -1
- package/dist/server/bare/rag-hyperdb/handlers/chunk.d.ts +3 -0
- package/dist/server/bare/rag-hyperdb/handlers/chunk.js +7 -0
- package/dist/server/bare/rag-hyperdb/handlers/close-workspace.d.ts +3 -0
- package/dist/server/bare/rag-hyperdb/handlers/close-workspace.js +9 -0
- package/dist/server/bare/rag-hyperdb/handlers/delete-embeddings.d.ts +1 -1
- package/dist/server/bare/rag-hyperdb/handlers/delete-embeddings.js +9 -10
- package/dist/server/bare/rag-hyperdb/handlers/delete-workspace.d.ts +3 -0
- package/dist/server/bare/rag-hyperdb/handlers/delete-workspace.js +14 -0
- package/dist/server/bare/rag-hyperdb/handlers/ingest.d.ts +9 -0
- package/dist/server/bare/rag-hyperdb/handlers/ingest.js +18 -0
- package/dist/server/bare/rag-hyperdb/handlers/list-workspaces.d.ts +3 -0
- package/dist/server/bare/rag-hyperdb/handlers/list-workspaces.js +4 -0
- package/dist/server/bare/rag-hyperdb/handlers/reindex.d.ts +9 -0
- package/dist/server/bare/rag-hyperdb/handlers/reindex.js +16 -0
- package/dist/server/bare/rag-hyperdb/handlers/save-embeddings.d.ts +7 -4
- package/dist/server/bare/rag-hyperdb/handlers/save-embeddings.js +13 -14
- package/dist/server/bare/rag-hyperdb/handlers/search.js +10 -10
- package/dist/server/bare/rag-hyperdb/index.d.ts +8 -1
- package/dist/server/bare/rag-hyperdb/index.js +8 -1
- package/dist/server/bare/rag-hyperdb/rag-operation-manager.d.ts +7 -0
- package/dist/server/bare/rag-hyperdb/rag-operation-manager.js +39 -0
- package/dist/server/bare/rag-hyperdb/rag-workspace-manager.d.ts +15 -0
- package/dist/server/bare/rag-hyperdb/rag-workspace-manager.js +135 -0
- package/dist/server/bare/registry/config-registry.js +11 -0
- package/dist/server/bare/registry/logging-stream-registry.js +3 -3
- package/dist/server/bare/registry/model-config-registry.d.ts +4 -0
- package/dist/server/bare/registry/model-config-registry.js +15 -0
- package/dist/server/bare/registry/model-config-utils.d.ts +15 -0
- package/dist/server/bare/registry/model-config-utils.js +110 -0
- package/dist/server/bare/registry/model-registry.d.ts +6 -29
- package/dist/server/bare/registry/runtime-context-registry.d.ts +7 -0
- package/dist/server/bare/registry/runtime-context-registry.js +26 -0
- package/dist/server/bare/utils/loader-adapter.d.ts +7 -0
- package/dist/server/bare/utils/loader-adapter.js +9 -0
- package/dist/server/error-handlers.js +4 -2
- package/dist/server/rpc/handle-request.js +91 -9
- package/dist/server/rpc/handlers/cancelHandler.js +10 -1
- package/dist/server/rpc/handlers/completion-stream.js +1 -1
- package/dist/server/rpc/handlers/delete-cache.js +1 -1
- package/dist/server/rpc/handlers/embed.js +1 -1
- package/dist/server/rpc/handlers/get-model-info.d.ts +1 -1
- package/dist/server/rpc/handlers/get-model-info.js +22 -10
- package/dist/server/rpc/handlers/index.d.ts +4 -1
- package/dist/server/rpc/handlers/index.js +2 -0
- package/dist/server/rpc/handlers/load-model/download-manager.d.ts +11 -11
- package/dist/server/rpc/handlers/load-model/download-manager.js +36 -26
- package/dist/server/rpc/handlers/{load-model.d.ts โ load-model/handler.d.ts} +2 -2
- package/dist/server/rpc/handlers/load-model/handler.js +179 -0
- package/dist/server/rpc/handlers/load-model/http.js +342 -33
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +5 -3
- package/dist/server/rpc/handlers/load-model/index.d.ts +2 -2
- package/dist/server/rpc/handlers/load-model/index.js +2 -2
- package/dist/server/rpc/handlers/load-model/resolve.js +32 -3
- package/dist/server/rpc/handlers/load-model-delegated.js +6 -3
- package/dist/server/rpc/handlers/ocr-stream.d.ts +3 -0
- package/dist/server/rpc/handlers/ocr-stream.js +39 -0
- package/dist/server/rpc/handlers/rag.d.ts +2 -2
- package/dist/server/rpc/handlers/rag.js +107 -43
- package/dist/server/rpc/handlers/text-to-speech.js +1 -1
- package/dist/server/rpc/handlers/transcribe-stream.js +1 -1
- package/dist/server/rpc/handlers/translate.js +6 -15
- package/dist/server/utils/archive.d.ts +3 -0
- package/dist/server/utils/archive.js +171 -0
- package/dist/server/utils/audio/decoder.js +2 -2
- package/dist/server/utils/cache.d.ts +5 -5
- package/dist/server/utils/cache.js +6 -6
- package/dist/server/utils/config-transform.d.ts +2 -2
- package/dist/server/utils/config-transform.js +8 -6
- package/dist/server/utils/formatting.d.ts +13 -0
- package/dist/server/utils/formatting.js +26 -0
- package/dist/server/utils/gguf-tensor-extractor.d.ts +15 -0
- package/dist/server/utils/gguf-tensor-extractor.js +314 -0
- package/dist/server/utils/index.d.ts +3 -1
- package/dist/server/utils/index.js +3 -1
- package/dist/server/utils/shard-utils.d.ts +42 -16
- package/dist/server/utils/shard-utils.js +95 -7
- package/dist/server/worker.js +8 -3
- package/dist/utils/errors-base.d.ts +1 -1
- package/dist/utils/errors-base.js +2 -2
- package/dist/utils/errors-client.d.ts +12 -0
- package/dist/utils/errors-client.js +20 -0
- package/dist/utils/errors-server.d.ts +33 -0
- package/dist/utils/errors-server.js +55 -0
- package/package.json +42 -17
- package/dist/client/rpc/bare-rpc-client.d.ts +0 -4
- package/dist/client/rpc/bare-rpc-client.js +0 -94
- package/dist/examples/config/config-path.d.ts +0 -8
- package/dist/examples/config/config-path.js +0 -13
- package/dist/examples/rag/rag-hyperdb-workspaces.d.ts +0 -2
- package/dist/examples/rag/rag-hyperdb-workspaces.js +0 -106
- package/dist/examples/rag/rag-hyperdb.d.ts +0 -2
- package/dist/server/bare/addons/llamacpp/index.d.ts +0 -4
- package/dist/server/bare/addons/llamacpp/index.js +0 -3
- package/dist/server/bare/rag-hyperdb/rag-manager.d.ts +0 -5
- package/dist/server/bare/rag-hyperdb/rag-manager.js +0 -66
- package/dist/server/rpc/handlers/load-model.js +0 -111
- package/dist/server/utils/hash.d.ts +0 -5
- package/dist/server/utils/hash.js +0 -11
- package/dist/utils/getProcessSafe.d.ts +0 -7
- package/dist/utils/getProcessSafe.js +0 -17
- package/dist/utils/runtime.d.ts +0 -30
- package/dist/utils/runtime.js +0 -48
- /package/dist/server/bare/addons/{llamacpp โ llamacpp-completion}/handlers/completion-stream.d.ts +0 -0
- /package/dist/server/bare/addons/{llamacpp โ llamacpp-embedding}/handlers/embed.d.ts +0 -0
- /package/dist/server/bare/addons/{llamacpp โ llamacpp-embedding}/handlers/embed.js +0 -0
- /package/dist/server/bare/addons/{translation โ nmtcpp-translation}/create-model.d.ts +0 -0
- /package/dist/server/bare/addons/{translation โ nmtcpp-translation}/handlers/translate.d.ts +0 -0
- /package/dist/server/bare/addons/{translation โ nmtcpp-translation}/index.d.ts +0 -0
- /package/dist/server/bare/addons/{translation โ nmtcpp-translation}/index.js +0 -0
- /package/dist/server/bare/addons/{tts โ onnx-tts}/create-model.d.ts +0 -0
- /package/dist/server/bare/addons/{tts โ onnx-tts}/create-model.js +0 -0
- /package/dist/server/bare/addons/{tts โ onnx-tts}/handlers/text-to-speech.d.ts +0 -0
- /package/dist/server/bare/addons/{tts โ onnx-tts}/handlers/text-to-speech.js +0 -0
- /package/dist/server/bare/addons/{tts โ onnx-tts}/index.d.ts +0 -0
- /package/dist/server/bare/addons/{tts โ onnx-tts}/index.js +0 -0
- /package/dist/server/bare/addons/{whispercpp โ whispercpp-transcription}/create-model.d.ts +0 -0
- /package/dist/server/bare/addons/{whispercpp โ whispercpp-transcription}/handlers/transcribe-stream.d.ts +0 -0
- /package/dist/server/bare/addons/{whispercpp โ whispercpp-transcription}/handlers/transcribe-stream.js +0 -0
- /package/dist/server/bare/addons/{whispercpp โ whispercpp-transcription}/index.d.ts +0 -0
- /package/dist/server/bare/addons/{whispercpp โ whispercpp-transcription}/index.js +0 -0
package/dist/client/api/rag.js
CHANGED
|
@@ -1,32 +1,122 @@
|
|
|
1
|
-
import { send } from "../rpc/rpc-client.js";
|
|
2
|
-
import { InvalidResponseError, InvalidOperationError, RAGSaveFailedError, RAGSearchFailedError, RAGDeleteFailedError, } from "../../utils/errors-client.js";
|
|
3
|
-
// ==============
|
|
1
|
+
import { send, stream } from "../rpc/rpc-client.js";
|
|
2
|
+
import { InvalidResponseError, InvalidOperationError, StreamEndedError, RAGChunkFailedError, RAGSaveFailedError, RAGSearchFailedError, RAGDeleteFailedError, RAGCloseWorkspaceFailedError, RAGListWorkspacesFailedError, } from "../../utils/errors-client.js";
|
|
3
|
+
// ============== Chunk ==============
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Chunks documents into smaller pieces for embedding.
|
|
6
|
+
* Part of the segregated flow: ragChunk() โ embed() โ ragSaveEmbeddings()
|
|
6
7
|
*
|
|
7
|
-
* @param params - The parameters for
|
|
8
|
-
* @param params.
|
|
9
|
-
* @param params.
|
|
10
|
-
* @
|
|
11
|
-
* @
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
14
|
-
*
|
|
8
|
+
* @param params - The parameters for chunking
|
|
9
|
+
* @param params.documents - Documents to chunk (string or array)
|
|
10
|
+
* @param params.chunkOpts - Chunking options (chunkSize, chunkOverlap, chunkStrategy)
|
|
11
|
+
* @returns Array of chunk results with id and content
|
|
12
|
+
* @throws {RAGChunkFailedError} When the operation fails
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const chunks = await ragChunk({
|
|
17
|
+
* documents: ["Long document text here..."],
|
|
18
|
+
* chunkOpts: {
|
|
19
|
+
* chunkSize: 256,
|
|
20
|
+
* chunkOverlap: 50,
|
|
21
|
+
* chunkStrategy: "paragraph",
|
|
22
|
+
* },
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
15
25
|
*/
|
|
16
|
-
export async function
|
|
26
|
+
export async function ragChunk(params) {
|
|
17
27
|
const request = {
|
|
18
28
|
type: "rag",
|
|
19
|
-
operation: "
|
|
29
|
+
operation: "chunk",
|
|
20
30
|
...params,
|
|
21
31
|
};
|
|
22
32
|
const response = await send(request);
|
|
23
33
|
if (response.type !== "rag") {
|
|
24
34
|
throw new InvalidResponseError("rag");
|
|
25
35
|
}
|
|
36
|
+
if (!response.success) {
|
|
37
|
+
throw new RAGChunkFailedError(response.error);
|
|
38
|
+
}
|
|
39
|
+
if (response.operation !== "chunk") {
|
|
40
|
+
throw new InvalidOperationError();
|
|
41
|
+
}
|
|
42
|
+
return response.chunks;
|
|
43
|
+
}
|
|
44
|
+
// ============== Ingest ==============
|
|
45
|
+
/**
|
|
46
|
+
* Ingests documents into the RAG vector database.
|
|
47
|
+
* Full pipeline: chunk โ embed โ save
|
|
48
|
+
*
|
|
49
|
+
* **Workspace lifecycle:** This operation implicitly opens (or creates) the workspace.
|
|
50
|
+
* The workspace remains open until closed.
|
|
51
|
+
*
|
|
52
|
+
* @param params - The parameters for ingestion
|
|
53
|
+
* @param params.modelId - The embedding model identifier
|
|
54
|
+
* @param params.documents - Documents to ingest (string or array)
|
|
55
|
+
* @param params.chunk - Whether to chunk documents (default: true)
|
|
56
|
+
* @param params.chunkOpts - Chunking options
|
|
57
|
+
* @param params.workspace - Workspace for isolated storage (default: "default"). Created if it doesn't exist.
|
|
58
|
+
* @param params.onProgress - Progress callback (stage, current, total)
|
|
59
|
+
* @param params.progressInterval - Minimum interval between progress updates in ms
|
|
60
|
+
* @returns Processing results and dropped indices
|
|
61
|
+
* @throws {RAGSaveFailedError} When the operation fails
|
|
62
|
+
* @throws {StreamEndedError} When streaming ends unexpectedly (only when using onProgress)
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* // Simple ingest
|
|
67
|
+
* const result = await ragIngest({
|
|
68
|
+
* modelId,
|
|
69
|
+
* documents: ["Document 1", "Document 2"],
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* // With progress tracking
|
|
73
|
+
* const result = await ragIngest({
|
|
74
|
+
* modelId,
|
|
75
|
+
* documents: ["Document 1", "Document 2"],
|
|
76
|
+
* workspace: "my-docs",
|
|
77
|
+
* onProgress: (stage, current, total) => {
|
|
78
|
+
* console.log(`[${stage}] ${current}/${total}`);
|
|
79
|
+
* },
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export async function ragIngest(params) {
|
|
84
|
+
const { onProgress, ...requestParams } = params;
|
|
85
|
+
const request = {
|
|
86
|
+
type: "rag",
|
|
87
|
+
operation: "ingest",
|
|
88
|
+
...requestParams,
|
|
89
|
+
chunk: requestParams.chunk ?? true,
|
|
90
|
+
withProgress: onProgress ? true : undefined,
|
|
91
|
+
};
|
|
92
|
+
if (onProgress) {
|
|
93
|
+
// Use streaming for progress updates
|
|
94
|
+
for await (const event of stream(request)) {
|
|
95
|
+
if (event.type === "rag:progress" && event.operation === "ingest") {
|
|
96
|
+
const progress = event;
|
|
97
|
+
onProgress(progress.stage, progress.current, progress.total);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (event.type === "rag" && event.operation === "ingest") {
|
|
101
|
+
if (!event.success) {
|
|
102
|
+
throw new RAGSaveFailedError(event.error);
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
processed: event.processed,
|
|
106
|
+
droppedIndices: event.droppedIndices,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
throw new StreamEndedError();
|
|
111
|
+
}
|
|
112
|
+
const response = await send(request);
|
|
113
|
+
if (response.type !== "rag") {
|
|
114
|
+
throw new InvalidResponseError("rag");
|
|
115
|
+
}
|
|
26
116
|
if (!response.success) {
|
|
27
117
|
throw new RAGSaveFailedError(response.error);
|
|
28
118
|
}
|
|
29
|
-
if (response.operation !== "
|
|
119
|
+
if (response.operation !== "ingest") {
|
|
30
120
|
throw new InvalidOperationError();
|
|
31
121
|
}
|
|
32
122
|
return {
|
|
@@ -34,18 +124,101 @@ export async function ragSaveEmbeddings(params) {
|
|
|
34
124
|
droppedIndices: response.droppedIndices,
|
|
35
125
|
};
|
|
36
126
|
}
|
|
127
|
+
// ============== SaveEmbeddings ==============
|
|
128
|
+
/**
|
|
129
|
+
* Saves pre-embedded documents to the RAG vector database.
|
|
130
|
+
* Part of the segregated flow: chunk() โ embed() โ saveEmbeddings()
|
|
131
|
+
*
|
|
132
|
+
* **Workspace lifecycle:** This operation implicitly opens (or creates) the workspace.
|
|
133
|
+
* The workspace remains open until closed.
|
|
134
|
+
*
|
|
135
|
+
* @param params - The parameters for saving
|
|
136
|
+
* @param params.documents - Pre-embedded documents (must have id, content, embedding, embeddingModelId)
|
|
137
|
+
* @param params.workspace - Workspace for isolated storage (default: "default"). Created if it doesn't exist.
|
|
138
|
+
* @param params.onProgress - Progress callback (stage, current, total)
|
|
139
|
+
* @param params.progressInterval - Minimum interval between progress updates in ms
|
|
140
|
+
* @returns Array of save results
|
|
141
|
+
* @throws {RAGSaveFailedError} When the operation fails
|
|
142
|
+
* @throws {StreamEndedError} When streaming ends unexpectedly (only when using onProgress)
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* // Segregated flow
|
|
147
|
+
* const chunks = await ragChunk({ documents: ["text1", "text2"] });
|
|
148
|
+
* const embeddings = await embed({ modelId, text: chunks.map(c => c.content) });
|
|
149
|
+
* const embeddedDocs = chunks.map((chunk, i) => ({
|
|
150
|
+
* ...chunk,
|
|
151
|
+
* embedding: embeddings[i],
|
|
152
|
+
* embeddingModelId: modelId,
|
|
153
|
+
* }));
|
|
154
|
+
* const result = await ragSaveEmbeddings({
|
|
155
|
+
* documents: embeddedDocs,
|
|
156
|
+
* workspace: "my-workspace",
|
|
157
|
+
* });
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export async function ragSaveEmbeddings(params) {
|
|
161
|
+
const { onProgress, ...requestParams } = params;
|
|
162
|
+
const request = {
|
|
163
|
+
type: "rag",
|
|
164
|
+
operation: "saveEmbeddings",
|
|
165
|
+
...requestParams,
|
|
166
|
+
withProgress: onProgress ? true : undefined,
|
|
167
|
+
};
|
|
168
|
+
if (onProgress) {
|
|
169
|
+
for await (const event of stream(request)) {
|
|
170
|
+
if (event.type === "rag:progress" &&
|
|
171
|
+
event.operation === "saveEmbeddings") {
|
|
172
|
+
const progress = event;
|
|
173
|
+
onProgress(progress.stage, progress.current, progress.total);
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (event.type === "rag" && event.operation === "saveEmbeddings") {
|
|
177
|
+
if (!event.success) {
|
|
178
|
+
throw new RAGSaveFailedError(event.error);
|
|
179
|
+
}
|
|
180
|
+
return event.processed;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
throw new StreamEndedError();
|
|
184
|
+
}
|
|
185
|
+
const response = await send(request);
|
|
186
|
+
if (response.type !== "rag") {
|
|
187
|
+
throw new InvalidResponseError("rag");
|
|
188
|
+
}
|
|
189
|
+
if (!response.success) {
|
|
190
|
+
throw new RAGSaveFailedError(response.error);
|
|
191
|
+
}
|
|
192
|
+
if (response.operation !== "saveEmbeddings") {
|
|
193
|
+
throw new InvalidOperationError();
|
|
194
|
+
}
|
|
195
|
+
return response.processed;
|
|
196
|
+
}
|
|
37
197
|
// ============== Search ==============
|
|
38
198
|
/**
|
|
39
199
|
* Searches for similar documents in the RAG vector database.
|
|
40
200
|
*
|
|
201
|
+
* **Workspace lifecycle:** This operation requires an existing workspace. If the workspace
|
|
202
|
+
* doesn't exist, returns an empty array.
|
|
203
|
+
*
|
|
41
204
|
* @param params - The parameters for searching
|
|
42
205
|
* @param params.modelId - The identifier of the embedding model to use
|
|
43
206
|
* @param params.query - The search query text
|
|
44
207
|
* @param params.topK - Number of top results to retrieve (default: 5)
|
|
45
208
|
* @param params.n - Number of centroids to use for IVF index search (default: 3)
|
|
46
|
-
* @param params.workspace -
|
|
47
|
-
* @
|
|
48
|
-
* @
|
|
209
|
+
* @param params.workspace - Workspace to search in (default: "default").
|
|
210
|
+
* @returns Array of search results with id, content, and score. Empty array if workspace doesn't exist.
|
|
211
|
+
* @throws {RAGSearchFailedError} When the operation fails
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* const results = await ragSearch({
|
|
216
|
+
* modelId,
|
|
217
|
+
* query: "AI and machine learning",
|
|
218
|
+
* topK: 5,
|
|
219
|
+
* workspace: "my-docs",
|
|
220
|
+
* });
|
|
221
|
+
* ```
|
|
49
222
|
*/
|
|
50
223
|
export async function ragSearch(params) {
|
|
51
224
|
const request = {
|
|
@@ -71,12 +244,20 @@ export async function ragSearch(params) {
|
|
|
71
244
|
/**
|
|
72
245
|
* Deletes document embeddings from the RAG vector database.
|
|
73
246
|
*
|
|
247
|
+
* **Workspace lifecycle:** This operation requires an existing workspace.
|
|
248
|
+
*
|
|
74
249
|
* @param params - The parameters for deleting embeddings
|
|
75
|
-
* @param params.modelId - The identifier of the embedding model (must match workspace model)
|
|
76
250
|
* @param params.ids - Array of document IDs to delete
|
|
77
|
-
* @param params.workspace -
|
|
78
|
-
* @throws {
|
|
79
|
-
*
|
|
251
|
+
* @param params.workspace - Workspace to delete from (default: "default")
|
|
252
|
+
* @throws {RAGDeleteFailedError} When the operation fails or workspace doesn't exist
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* await ragDeleteEmbeddings({
|
|
257
|
+
* ids: ["doc-1", "doc-2"],
|
|
258
|
+
* workspace: "my-docs",
|
|
259
|
+
* });
|
|
260
|
+
* ```
|
|
80
261
|
*/
|
|
81
262
|
export async function ragDeleteEmbeddings(params) {
|
|
82
263
|
const request = {
|
|
@@ -94,5 +275,183 @@ export async function ragDeleteEmbeddings(params) {
|
|
|
94
275
|
if (response.operation !== "deleteEmbeddings") {
|
|
95
276
|
throw new InvalidOperationError();
|
|
96
277
|
}
|
|
97
|
-
|
|
278
|
+
}
|
|
279
|
+
// ============== Reindex ==============
|
|
280
|
+
/**
|
|
281
|
+
* Reindexes the RAG database to optimize search performance.
|
|
282
|
+
* For HyperDB, this rebalances centroids using k-means clustering.
|
|
283
|
+
*
|
|
284
|
+
* **Workspace lifecycle:** This operation requires an existing workspace.
|
|
285
|
+
*
|
|
286
|
+
* **Note:** Reindex requires a minimum number of documents to perform clustering.
|
|
287
|
+
* For HyperDB, this is 16 documents by default. If there are insufficient documents,
|
|
288
|
+
* `reindexed` will be `false` with `details` explaining the reason.
|
|
289
|
+
*
|
|
290
|
+
* @param params - The parameters for reindexing
|
|
291
|
+
* @param params.workspace - Workspace to reindex (default: "default"). Must already exist.
|
|
292
|
+
* @param params.onProgress - Progress callback (stage, current, total)
|
|
293
|
+
* @returns Reindex result with `reindexed` boolean and optional `details`
|
|
294
|
+
* @throws {RAGSaveFailedError} When the operation fails or workspace doesn't exist
|
|
295
|
+
* @throws {StreamEndedError} When streaming ends unexpectedly (only when using onProgress)
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* ```typescript
|
|
299
|
+
* // Simple reindex
|
|
300
|
+
* const result = await ragReindex({
|
|
301
|
+
* workspace: "my-docs",
|
|
302
|
+
* });
|
|
303
|
+
*
|
|
304
|
+
* // Check result
|
|
305
|
+
* if (!result.reindexed) {
|
|
306
|
+
* console.log("Reindex skipped:", result.details?.reason);
|
|
307
|
+
* }
|
|
308
|
+
*
|
|
309
|
+
* // With progress tracking
|
|
310
|
+
* const result = await ragReindex({
|
|
311
|
+
* workspace: "my-docs",
|
|
312
|
+
* onProgress: (stage, current, total) => {
|
|
313
|
+
* console.log(`[${stage}] ${current}/${total}`);
|
|
314
|
+
* },
|
|
315
|
+
* });
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
export async function ragReindex(params) {
|
|
319
|
+
const { onProgress, ...requestParams } = params;
|
|
320
|
+
const request = {
|
|
321
|
+
type: "rag",
|
|
322
|
+
operation: "reindex",
|
|
323
|
+
...requestParams,
|
|
324
|
+
withProgress: onProgress ? true : undefined,
|
|
325
|
+
};
|
|
326
|
+
if (onProgress) {
|
|
327
|
+
for await (const event of stream(request)) {
|
|
328
|
+
if (event.type === "rag:progress" && event.operation === "reindex") {
|
|
329
|
+
const progress = event;
|
|
330
|
+
onProgress(progress.stage, progress.current, progress.total);
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
if (event.type === "rag" && event.operation === "reindex") {
|
|
334
|
+
if (!event.success) {
|
|
335
|
+
throw new RAGSaveFailedError(event.error);
|
|
336
|
+
}
|
|
337
|
+
return event.result;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
throw new StreamEndedError();
|
|
341
|
+
}
|
|
342
|
+
const response = await send(request);
|
|
343
|
+
if (response.type !== "rag") {
|
|
344
|
+
throw new InvalidResponseError("rag");
|
|
345
|
+
}
|
|
346
|
+
if (!response.success) {
|
|
347
|
+
throw new RAGSaveFailedError(response.error);
|
|
348
|
+
}
|
|
349
|
+
if (response.operation !== "reindex") {
|
|
350
|
+
throw new InvalidOperationError();
|
|
351
|
+
}
|
|
352
|
+
return response.result;
|
|
353
|
+
}
|
|
354
|
+
// ============== List Workspaces ==============
|
|
355
|
+
/**
|
|
356
|
+
* Lists all RAG workspaces with their open status.
|
|
357
|
+
*
|
|
358
|
+
* Returns all workspaces that exist on disk. The `open` field indicates whether
|
|
359
|
+
* the workspace is currently loaded in memory and holding active resources
|
|
360
|
+
* (Corestore, HyperDB adapter, and possibly a RAG instance).
|
|
361
|
+
*
|
|
362
|
+
* @returns Array of workspace info with name and open status
|
|
363
|
+
* @throws {RAGListWorkspacesFailedError} When the operation fails
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* ```typescript
|
|
367
|
+
* const workspaces = await ragListWorkspaces();
|
|
368
|
+
* // [{ name: "default", open: true }, { name: "my-docs", open: false }]
|
|
369
|
+
* ```
|
|
370
|
+
*/
|
|
371
|
+
export async function ragListWorkspaces() {
|
|
372
|
+
const request = {
|
|
373
|
+
type: "rag",
|
|
374
|
+
operation: "listWorkspaces",
|
|
375
|
+
};
|
|
376
|
+
const response = await send(request);
|
|
377
|
+
if (response.type !== "rag") {
|
|
378
|
+
throw new InvalidResponseError("rag");
|
|
379
|
+
}
|
|
380
|
+
if (!response.success) {
|
|
381
|
+
throw new RAGListWorkspacesFailedError(response.error);
|
|
382
|
+
}
|
|
383
|
+
if (response.operation !== "listWorkspaces") {
|
|
384
|
+
throw new InvalidOperationError();
|
|
385
|
+
}
|
|
386
|
+
return response.workspaces;
|
|
387
|
+
}
|
|
388
|
+
// ============== Close Workspace ==============
|
|
389
|
+
/**
|
|
390
|
+
* Closes a RAG workspace, releasing in-memory resources (Corestore, HyperDB adapter, RAG instance).
|
|
391
|
+
*
|
|
392
|
+
* **Workspace lifecycle:** Workspaces are implicitly opened.
|
|
393
|
+
* This function explicitly closes them, releasing memory and file locks. The workspace data
|
|
394
|
+
* remains on disk unless `deleteOnClose` is set to true.
|
|
395
|
+
*
|
|
396
|
+
* @param params - The parameters for closing
|
|
397
|
+
* @param params.workspace - Name of the workspace to close (default: "default")
|
|
398
|
+
* @param params.deleteOnClose - If true, deletes the workspace data from disk after closing (default: false)
|
|
399
|
+
* @throws {RAGCloseWorkspaceFailedError} When the operation fails
|
|
400
|
+
*
|
|
401
|
+
* @example
|
|
402
|
+
* ```typescript
|
|
403
|
+
* // Close a specific workspace
|
|
404
|
+
* await ragCloseWorkspace({ workspace: "my-docs" });
|
|
405
|
+
*
|
|
406
|
+
* // Close and delete in one call
|
|
407
|
+
* await ragCloseWorkspace({ workspace: "my-docs", deleteOnClose: true });
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
export async function ragCloseWorkspace(params) {
|
|
411
|
+
const request = {
|
|
412
|
+
type: "rag",
|
|
413
|
+
operation: "closeWorkspace",
|
|
414
|
+
...params,
|
|
415
|
+
};
|
|
416
|
+
const response = await send(request);
|
|
417
|
+
if (response.type !== "rag") {
|
|
418
|
+
throw new InvalidResponseError("rag");
|
|
419
|
+
}
|
|
420
|
+
if (!response.success) {
|
|
421
|
+
throw new RAGCloseWorkspaceFailedError(response.error);
|
|
422
|
+
}
|
|
423
|
+
if (response.operation !== "closeWorkspace") {
|
|
424
|
+
throw new InvalidOperationError();
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
// ============== Delete Workspace ==============
|
|
428
|
+
/**
|
|
429
|
+
* Deletes a RAG workspace and all its data.
|
|
430
|
+
* The workspace must not be currently loaded/in-use.
|
|
431
|
+
*
|
|
432
|
+
* @param params - The parameters for deletion
|
|
433
|
+
* @param params.workspace - Name of the workspace to delete
|
|
434
|
+
* @throws {RAGDeleteFailedError} When the workspace doesn't exist or is currently loaded
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
* ```typescript
|
|
438
|
+
* await ragDeleteWorkspace({ workspace: "my-docs" });
|
|
439
|
+
* ```
|
|
440
|
+
*/
|
|
441
|
+
export async function ragDeleteWorkspace(params) {
|
|
442
|
+
const request = {
|
|
443
|
+
type: "rag",
|
|
444
|
+
operation: "deleteWorkspace",
|
|
445
|
+
...params,
|
|
446
|
+
};
|
|
447
|
+
const response = await send(request);
|
|
448
|
+
if (response.type !== "rag") {
|
|
449
|
+
throw new InvalidResponseError("rag");
|
|
450
|
+
}
|
|
451
|
+
if (!response.success) {
|
|
452
|
+
throw new RAGDeleteFailedError(response.error);
|
|
453
|
+
}
|
|
454
|
+
if (response.operation !== "deleteWorkspace") {
|
|
455
|
+
throw new InvalidOperationError();
|
|
456
|
+
}
|
|
98
457
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { stream as streamRpc } from "../rpc/rpc-client.js";
|
|
2
|
-
import { translateResponseSchema, } from "../../schemas/index.js";
|
|
2
|
+
import { translateResponseSchema, normalizeModelType, ModelType, } from "../../schemas/index.js";
|
|
3
3
|
import { detectOne } from "@qvac/langdetect-text";
|
|
4
4
|
import { TranslationFailedError } from "../../utils/errors-client.js";
|
|
5
5
|
/**
|
|
@@ -43,21 +43,20 @@ import { TranslationFailedError } from "../../utils/errors-client.js";
|
|
|
43
43
|
* ```
|
|
44
44
|
*/
|
|
45
45
|
export function translate(params) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
sourceLanguage = detected.language;
|
|
46
|
+
const canonicalModelType = normalizeModelType(params.modelType);
|
|
47
|
+
const isLlm = canonicalModelType === ModelType.llamacppCompletion;
|
|
48
|
+
let sourceLanguage = isLlm ? params.from : undefined;
|
|
49
|
+
if (!sourceLanguage && isLlm) {
|
|
50
|
+
const detected = detectOne(params.text);
|
|
51
|
+
if (detected.code === "und" || detected.language === "Undetermined") {
|
|
52
|
+
throw new TranslationFailedError("Could not detect the source language. Please specify the 'from' parameter explicitly.");
|
|
55
53
|
}
|
|
54
|
+
sourceLanguage = detected.language;
|
|
56
55
|
}
|
|
57
56
|
const request = {
|
|
58
57
|
type: "translate",
|
|
59
58
|
...params,
|
|
60
|
-
...(
|
|
59
|
+
...(isLlm && {
|
|
61
60
|
from: sourceLanguage,
|
|
62
61
|
}),
|
|
63
62
|
};
|
|
@@ -34,6 +34,6 @@ export async function unloadModel(params) {
|
|
|
34
34
|
if (response.hasActiveModels === false &&
|
|
35
35
|
response.hasActiveProviders === false) {
|
|
36
36
|
logger.info("๐งน No models or providers active, automatically closing RPC connection...");
|
|
37
|
-
|
|
37
|
+
close();
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import type { QvacConfig } from "../schemas/index";
|
|
1
|
+
import type { QvacConfig, RuntimeContext } from "../schemas/index";
|
|
2
2
|
type ResolveConfigFn = () => Promise<QvacConfig | undefined>;
|
|
3
3
|
interface RPCClient {
|
|
4
4
|
request(command: number): any;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Initializes SDK configuration and runtime context.
|
|
8
8
|
* Config is loaded once and becomes immutable on the worker side.
|
|
9
9
|
*
|
|
10
10
|
* @param rpc - The RPC client instance
|
|
11
11
|
* @param resolveConfig - Runtime-specific config resolver function
|
|
12
|
+
* @param runtimeContext - Optional runtime context (platform, device info)
|
|
12
13
|
*/
|
|
13
|
-
export declare function initializeConfig(rpc: RPCClient, resolveConfig: ResolveConfigFn): Promise<void>;
|
|
14
|
+
export declare function initializeConfig(rpc: RPCClient, resolveConfig: ResolveConfigFn, runtimeContext?: RuntimeContext): Promise<void>;
|
|
14
15
|
/**
|
|
15
16
|
* Legacy function for backward compatibility
|
|
16
17
|
* @deprecated Use initializeConfig instead
|
|
@@ -1,50 +1,59 @@
|
|
|
1
1
|
import { getClientLogger, setGlobalLogLevel, setGlobalConsoleOutput, } from "../logging/index.js";
|
|
2
2
|
const logger = getClientLogger();
|
|
3
|
+
function applyClientLoggerSettings(config) {
|
|
4
|
+
if (config.loggerLevel !== undefined) {
|
|
5
|
+
setGlobalLogLevel(config.loggerLevel);
|
|
6
|
+
}
|
|
7
|
+
if (config.loggerConsoleOutput !== undefined) {
|
|
8
|
+
setGlobalConsoleOutput(config.loggerConsoleOutput);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
async function sendInitMessage(rpc, config, runtimeContext) {
|
|
12
|
+
const initMessage = {
|
|
13
|
+
type: "__init_config",
|
|
14
|
+
config,
|
|
15
|
+
runtimeContext,
|
|
16
|
+
};
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
18
|
+
const req = rpc.request(1);
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
20
|
+
req.send(JSON.stringify(initMessage), "utf8");
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
22
|
+
const response = await req.reply("utf8");
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument
|
|
24
|
+
const parsed = JSON.parse(response.toString());
|
|
25
|
+
if (!parsed.success) {
|
|
26
|
+
throw new Error(parsed.error ?? "Unknown error");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
3
29
|
/**
|
|
4
|
-
*
|
|
30
|
+
* Initializes SDK configuration and runtime context.
|
|
5
31
|
* Config is loaded once and becomes immutable on the worker side.
|
|
6
32
|
*
|
|
7
33
|
* @param rpc - The RPC client instance
|
|
8
34
|
* @param resolveConfig - Runtime-specific config resolver function
|
|
35
|
+
* @param runtimeContext - Optional runtime context (platform, device info)
|
|
9
36
|
*/
|
|
10
|
-
export async function initializeConfig(rpc, resolveConfig) {
|
|
37
|
+
export async function initializeConfig(rpc, resolveConfig, runtimeContext) {
|
|
11
38
|
const config = await resolveConfig();
|
|
12
|
-
|
|
13
|
-
|
|
39
|
+
// Nothing to initialize
|
|
40
|
+
if (!config && !runtimeContext) {
|
|
14
41
|
return;
|
|
15
42
|
}
|
|
16
|
-
// Apply logger settings
|
|
17
|
-
if (config
|
|
18
|
-
|
|
43
|
+
// Apply client-side logger settings
|
|
44
|
+
if (config) {
|
|
45
|
+
applyClientLoggerSettings(config);
|
|
46
|
+
logger.info("๐ฆ Initializing SDK config");
|
|
19
47
|
}
|
|
20
|
-
if (
|
|
21
|
-
|
|
48
|
+
if (runtimeContext) {
|
|
49
|
+
logger.info("๐ฑ Runtime context:", runtimeContext);
|
|
22
50
|
}
|
|
23
|
-
logger.info("๐ฆ Initializing config:", config);
|
|
24
51
|
try {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const initMessage = {
|
|
28
|
-
type: "__init_config",
|
|
29
|
-
config,
|
|
30
|
-
};
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
32
|
-
const req = rpc.request(1);
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
34
|
-
req.send(JSON.stringify(initMessage), "utf8");
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
36
|
-
const response = await req.reply("utf8");
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument
|
|
38
|
-
const parsed = JSON.parse(response.toString());
|
|
39
|
-
if (!parsed.success) {
|
|
40
|
-
logger.error("โ Failed to initialize config:", parsed.error);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
logger.info("โ
Config successfully initialized");
|
|
44
|
-
}
|
|
52
|
+
await sendInitMessage(rpc, config, runtimeContext);
|
|
53
|
+
logger.info("โ
Initialization complete");
|
|
45
54
|
}
|
|
46
55
|
catch (error) {
|
|
47
|
-
logger.error("โ
|
|
56
|
+
logger.error("โ Initialization failed:", error);
|
|
48
57
|
}
|
|
49
58
|
}
|
|
50
59
|
/**
|