@qvac/sdk 0.7.1 → 0.8.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/NOTICE +73 -10
- package/README.md +4 -4
- package/bare-imports.json +9 -0
- package/dist/client/api/cancel.d.ts +9 -0
- package/dist/client/api/cancel.js +9 -0
- package/dist/client/api/completion-stream.d.ts +2 -1
- package/dist/client/api/completion-stream.js +2 -1
- package/dist/client/api/download-asset.d.ts +3 -2
- package/dist/client/api/download-asset.js +4 -3
- package/dist/client/api/embed.d.ts +5 -2
- package/dist/client/api/embed.js +2 -2
- package/dist/client/api/get-model-info.d.ts +1 -1
- package/dist/client/api/heartbeat.d.ts +30 -0
- package/dist/client/api/heartbeat.js +38 -0
- package/dist/client/api/index.d.ts +1 -1
- package/dist/client/api/index.js +1 -1
- package/dist/client/api/invoke-plugin.d.ts +3 -2
- package/dist/client/api/invoke-plugin.js +4 -4
- package/dist/client/api/load-model.d.ts +12 -10
- package/dist/client/api/load-model.js +3 -3
- package/dist/client/api/rag.d.ts +10 -10
- package/dist/client/api/rag.js +21 -21
- package/dist/client/api/text-to-speech.d.ts +2 -2
- package/dist/client/api/text-to-speech.js +3 -3
- package/dist/client/api/transcribe.d.ts +5 -3
- package/dist/client/api/transcribe.js +6 -4
- package/dist/client/api/translate.d.ts +2 -2
- package/dist/client/api/translate.js +3 -3
- package/dist/client/rpc/node-rpc-client.d.ts +2 -7
- package/dist/client/rpc/node-rpc-client.js +2 -39
- package/dist/client/rpc/profiling/index.d.ts +2 -0
- package/dist/client/rpc/profiling/index.js +1 -0
- package/dist/client/rpc/profiling/profiler.d.ts +27 -0
- package/dist/client/rpc/profiling/profiler.js +139 -0
- package/dist/client/rpc/rpc-client.d.ts +2 -2
- package/dist/client/rpc/rpc-client.js +174 -12
- package/dist/examples/delegated-inference/consumer-profiled.d.ts +2 -0
- package/dist/examples/delegated-inference/consumer-profiled.js +67 -0
- package/dist/examples/embed-p2p.d.ts +2 -0
- package/dist/examples/llamacpp-multimodal.js +1 -1
- package/dist/examples/llamacpp-p2p.d.ts +2 -0
- package/dist/examples/parallel-download.js +45 -13
- package/dist/examples/profiling/basic.d.ts +2 -0
- package/dist/examples/profiling/basic.js +71 -0
- package/dist/examples/profiling/per-call.d.ts +2 -0
- package/dist/examples/profiling/per-call.js +30 -0
- package/dist/examples/seed-p2p.d.ts +2 -0
- package/dist/examples/transcription/parakeet-ctc-filesystem.d.ts +2 -0
- package/dist/examples/transcription/parakeet-ctc-filesystem.js +40 -0
- package/dist/examples/transcription/parakeet-microphone-record.d.ts +2 -0
- package/dist/examples/transcription/parakeet-microphone-record.js +95 -0
- package/dist/examples/transcription/parakeet-sortformer.d.ts +2 -0
- package/dist/examples/transcription/parakeet-sortformer.js +115 -0
- package/dist/examples/transcription/parakeet-tdt-filesystem.d.ts +2 -0
- package/dist/examples/transcription/parakeet-tdt-filesystem.js +44 -0
- package/dist/examples/translation/translation-bergamot-pivot.d.ts +2 -0
- package/dist/examples/translation/translation-bergamot-pivot.js +73 -0
- package/dist/examples/translation/translation-llm-afriquegemma.d.ts +2 -0
- package/dist/examples/translation/translation-llm-afriquegemma.js +39 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -1
- package/dist/logging/index.d.ts +1 -1
- package/dist/logging/index.js +1 -1
- package/dist/logging/namespaces.d.ts +3 -9
- package/dist/logging/namespaces.js +2 -8
- package/dist/logging/registry.js +15 -1
- package/dist/models/registry/models.d.ts +1671 -310
- package/dist/models/registry/models.js +2116 -710
- package/dist/models/update-models/codegen.js +2 -2
- package/dist/models/update-models/history.d.ts +11 -0
- package/dist/models/update-models/history.js +24 -5
- package/dist/models/update-models/index.js +17 -16
- package/dist/models/update-models/naming.js +56 -0
- package/dist/profiling/aggregator.d.ts +15 -0
- package/dist/profiling/aggregator.js +100 -0
- package/dist/profiling/clock.d.ts +12 -0
- package/dist/profiling/clock.js +51 -0
- package/dist/profiling/controller.d.ts +33 -0
- package/dist/profiling/controller.js +123 -0
- package/dist/profiling/envelope.d.ts +10 -0
- package/dist/profiling/envelope.js +36 -0
- package/dist/profiling/events.d.ts +20 -0
- package/dist/profiling/events.js +37 -0
- package/dist/profiling/exporters.d.ts +10 -0
- package/dist/profiling/exporters.js +236 -0
- package/dist/profiling/index.d.ts +36 -0
- package/dist/profiling/index.js +31 -0
- package/dist/profiling/ring-buffer.d.ts +19 -0
- package/dist/profiling/ring-buffer.js +83 -0
- package/dist/profiling/types.d.ts +47 -0
- package/dist/profiling/types.js +1 -0
- package/dist/schemas/cancel.d.ts +12 -0
- package/dist/schemas/cancel.js +2 -0
- package/dist/schemas/common.d.ts +1927 -135
- package/dist/schemas/common.js +6 -3
- package/dist/schemas/completion-stream.d.ts +31 -0
- package/dist/schemas/completion-stream.js +13 -0
- package/dist/schemas/delegate.d.ts +8 -0
- package/dist/schemas/delegate.js +5 -2
- package/dist/schemas/download-asset.d.ts +14 -3
- package/dist/schemas/download-asset.js +3 -1
- package/dist/schemas/engine-addon-map.js +9 -6
- package/dist/schemas/get-model-info.d.ts +2 -0
- package/dist/schemas/get-model-info.js +1 -0
- package/dist/schemas/heartbeat.d.ts +17 -0
- package/dist/schemas/heartbeat.js +10 -0
- package/dist/schemas/index.d.ts +3 -2
- package/dist/schemas/index.js +3 -2
- package/dist/schemas/llamacpp-config.d.ts +140 -14
- package/dist/schemas/llamacpp-config.js +11 -7
- package/dist/schemas/load-model.d.ts +9762 -2515
- package/dist/schemas/load-model.js +142 -182
- package/dist/schemas/model-src-utils.d.ts +10 -2
- package/dist/schemas/model-types.d.ts +19 -1
- package/dist/schemas/model-types.js +11 -0
- package/dist/schemas/ocr.d.ts +37 -0
- package/dist/schemas/ocr.js +5 -0
- package/dist/schemas/plugin.d.ts +51 -5
- package/dist/schemas/plugin.js +26 -0
- package/dist/schemas/profiling.d.ts +105 -0
- package/dist/schemas/profiling.js +66 -0
- package/dist/schemas/registry.d.ts +18 -0
- package/dist/schemas/registry.js +2 -0
- package/dist/schemas/reload-config.d.ts +126 -6
- package/dist/schemas/reload-config.js +1 -1
- package/dist/schemas/sdk-config.d.ts +2280 -24
- package/dist/schemas/sdk-config.js +6 -1
- package/dist/schemas/sdk-errors-client.d.ts +1 -0
- package/dist/schemas/sdk-errors-client.js +7 -0
- package/dist/schemas/sdk-errors-server.d.ts +3 -0
- package/dist/schemas/sdk-errors-server.js +15 -0
- package/dist/schemas/text-to-speech.d.ts +90 -68
- package/dist/schemas/text-to-speech.js +16 -33
- package/dist/schemas/transcription-config.d.ts +383 -0
- package/dist/schemas/{whispercpp-config.js → transcription-config.js} +29 -1
- package/dist/schemas/translation-config.d.ts +463 -8
- package/dist/schemas/translation-config.js +35 -2
- package/dist/server/bare/delegate-rpc-client.js +52 -11
- package/dist/server/bare/ops/load-model.d.ts +7 -1
- package/dist/server/bare/ops/load-model.js +41 -42
- package/dist/server/bare/ops/transcribe.d.ts +3 -0
- package/dist/server/bare/ops/transcribe.js +75 -0
- package/dist/server/bare/ops/translate.d.ts +2 -0
- package/dist/server/bare/ops/translate.js +12 -4
- package/dist/server/bare/plugins/index.d.ts +1 -0
- package/dist/server/bare/plugins/index.js +1 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.d.ts +2 -1
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.js +8 -6
- package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +108 -3
- package/dist/server/bare/plugins/llamacpp-completion/plugin.js +19 -6
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.d.ts +32 -2
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.js +31 -17
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +325 -3
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.js +117 -13
- package/dist/server/bare/plugins/onnx-ocr/plugin.d.ts +50 -2
- package/dist/server/bare/plugins/onnx-ocr/plugin.js +46 -5
- package/dist/server/bare/plugins/onnx-tts/plugin.d.ts +351 -4
- package/dist/server/bare/plugins/onnx-tts/plugin.js +81 -61
- package/dist/server/bare/plugins/parakeet-transcription/plugin.d.ts +317 -0
- package/dist/server/bare/plugins/parakeet-transcription/plugin.js +154 -0
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +209 -3
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +21 -9
- package/dist/server/bare/rag-hyperdb/rag-workspace-manager.js +2 -2
- package/dist/server/bare/registry/model-config-utils.js +3 -1
- package/dist/server/bare/registry/model-registry.d.ts +2 -0
- package/dist/server/bare/registry/model-registry.js +2 -1
- package/dist/server/bare/utils/audio-input.d.ts +10 -0
- package/dist/server/bare/utils/audio-input.js +33 -0
- package/dist/server/error-handlers.d.ts +3 -2
- package/dist/server/error-handlers.js +11 -8
- package/dist/server/plugins/registry.js +5 -1
- package/dist/server/rpc/delegate-transport.d.ts +11 -3
- package/dist/server/rpc/delegate-transport.js +214 -38
- package/dist/server/rpc/delegate-utils.d.ts +2 -0
- package/dist/server/rpc/delegate-utils.js +5 -0
- package/dist/server/rpc/handle-request.js +43 -4
- package/dist/server/rpc/handler-registry.js +33 -4
- package/dist/server/rpc/handler-utils.d.ts +5 -4
- package/dist/server/rpc/handler-utils.js +114 -31
- package/dist/server/rpc/handlers/cancel-delegated.d.ts +4 -0
- package/dist/server/rpc/handlers/cancel-delegated.js +71 -0
- package/dist/server/rpc/handlers/completion-stream-delegated.d.ts +3 -1
- package/dist/server/rpc/handlers/completion-stream-delegated.js +13 -4
- package/dist/server/rpc/handlers/download-asset.js +55 -3
- package/dist/server/rpc/handlers/heartbeat-delegated.d.ts +4 -0
- package/dist/server/rpc/handlers/heartbeat-delegated.js +32 -0
- package/dist/server/rpc/handlers/heartbeat.d.ts +3 -0
- package/dist/server/rpc/handlers/heartbeat.js +3 -0
- package/dist/server/rpc/handlers/index.d.ts +2 -2
- package/dist/server/rpc/handlers/index.js +2 -2
- package/dist/server/rpc/handlers/load-model/download-stats.d.ts +6 -0
- package/dist/server/rpc/handlers/load-model/download-stats.js +87 -0
- package/dist/server/rpc/handlers/load-model/handler.js +108 -123
- package/dist/server/rpc/handlers/load-model/http.d.ts +2 -1
- package/dist/server/rpc/handlers/load-model/http.js +21 -5
- package/dist/server/rpc/handlers/load-model/hyperdrive.d.ts +2 -1
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +19 -14
- package/dist/server/rpc/handlers/load-model/registry.d.ts +2 -1
- package/dist/server/rpc/handlers/load-model/registry.js +113 -136
- package/dist/server/rpc/handlers/load-model/resolve.d.ts +2 -0
- package/dist/server/rpc/handlers/load-model/resolve.js +55 -22
- package/dist/server/rpc/handlers/load-model/types.d.ts +29 -0
- package/dist/server/rpc/handlers/load-model/types.js +1 -0
- package/dist/server/rpc/handlers/load-model-delegated.d.ts +5 -1
- package/dist/server/rpc/handlers/load-model-delegated.js +41 -11
- package/dist/server/rpc/handlers/plugin-dispatch.js +15 -10
- package/dist/server/rpc/handlers/plugin-invoke.js +56 -51
- package/dist/server/rpc/handlers/rag.js +24 -0
- package/dist/server/rpc/handlers/unload-model-delegated.d.ts +3 -0
- package/dist/server/rpc/handlers/unload-model-delegated.js +32 -0
- package/dist/server/rpc/profiling/context.d.ts +18 -0
- package/dist/server/rpc/profiling/context.js +38 -0
- package/dist/server/rpc/profiling/delegation-profiler.d.ts +32 -0
- package/dist/server/rpc/profiling/delegation-profiler.js +154 -0
- package/dist/server/rpc/profiling/index.d.ts +5 -0
- package/dist/server/rpc/profiling/index.js +4 -0
- package/dist/server/rpc/profiling/operation-metrics.d.ts +25 -0
- package/dist/server/rpc/profiling/operation-metrics.js +199 -0
- package/dist/server/rpc/profiling/operation-wrappers.d.ts +18 -0
- package/dist/server/rpc/profiling/operation-wrappers.js +124 -0
- package/dist/server/rpc/profiling/profiler.d.ts +13 -0
- package/dist/server/rpc/profiling/profiler.js +97 -0
- package/dist/server/utils/cache.d.ts +2 -1
- package/dist/server/utils/cache.js +5 -1
- package/dist/server/utils/checksum.d.ts +2 -0
- package/dist/server/utils/checksum.js +7 -0
- package/dist/server/utils/formatting.d.ts +6 -0
- package/dist/server/utils/formatting.js +35 -0
- package/dist/server/worker.js +2 -1
- package/dist/utils/errors-client.d.ts +3 -0
- package/dist/utils/errors-client.js +6 -0
- package/dist/utils/errors-server.d.ts +9 -0
- package/dist/utils/errors-server.js +15 -0
- package/dist/utils/global-singleton.d.ts +2 -0
- package/dist/utils/global-singleton.js +10 -0
- package/package.json +22 -18
- package/dist/client/api/ping.d.ts +0 -11
- package/dist/client/api/ping.js +0 -19
- package/dist/examples/embed-hyperdrive.d.ts +0 -2
- package/dist/examples/llamacpp-hyperdrive.d.ts +0 -2
- package/dist/examples/seed-hyperdrive.d.ts +0 -2
- package/dist/schemas/ping.d.ts +0 -11
- package/dist/schemas/ping.js +0 -8
- package/dist/schemas/whispercpp-config.d.ts +0 -70
- package/dist/server/bare/plugins/whispercpp-transcription/ops/transcribe-stream.d.ts +0 -3
- package/dist/server/bare/plugins/whispercpp-transcription/ops/transcribe-stream.js +0 -81
- package/dist/server/rpc/handlers/ping.d.ts +0 -3
- package/dist/server/rpc/handlers/ping.js +0 -3
- /package/dist/examples/{embed-hyperdrive.js → embed-p2p.js} +0 -0
- /package/dist/examples/{llamacpp-hyperdrive.js → llamacpp-p2p.js} +0 -0
- /package/dist/examples/{seed-hyperdrive.js → seed-p2p.js} +0 -0
- /package/dist/examples/{whispercpp-filesystem.d.ts → transcription/whispercpp-filesystem.d.ts} +0 -0
- /package/dist/examples/{whispercpp-filesystem.js → transcription/whispercpp-filesystem.js} +0 -0
- /package/dist/examples/{whispercpp-microphone-record.d.ts → transcription/whispercpp-microphone-record.d.ts} +0 -0
- /package/dist/examples/{whispercpp-microphone-record.js → transcription/whispercpp-microphone-record.js} +0 -0
- /package/dist/examples/{whispercpp-prompt.d.ts → transcription/whispercpp-prompt.d.ts} +0 -0
- /package/dist/examples/{whispercpp-prompt.js → transcription/whispercpp-prompt.js} +0 -0
package/dist/client/api/rag.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RagChunkParams, RagDoc, RagIngestParams, RagSaveEmbeddingsParams, RagSaveEmbeddingsResult, RagSearchParams, RagSearchResult, RagDeleteEmbeddingsParams, RagReindexParams, RagReindexResult, RagWorkspaceInfo, RagCloseWorkspaceParams, RagDeleteWorkspaceParams } from "../../schemas/index";
|
|
1
|
+
import type { RagChunkParams, RagDoc, RagIngestParams, RagSaveEmbeddingsParams, RagSaveEmbeddingsResult, RagSearchParams, RagSearchResult, RagDeleteEmbeddingsParams, RagReindexParams, RagReindexResult, RagWorkspaceInfo, RagCloseWorkspaceParams, RagDeleteWorkspaceParams, RPCOptions } from "../../schemas/index";
|
|
2
2
|
/**
|
|
3
3
|
* Chunks documents into smaller pieces for embedding.
|
|
4
4
|
* Part of the segregated flow: ragChunk() → embed() → ragSaveEmbeddings()
|
|
@@ -21,7 +21,7 @@ import type { RagChunkParams, RagDoc, RagIngestParams, RagSaveEmbeddingsParams,
|
|
|
21
21
|
* });
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
export declare function ragChunk(params: RagChunkParams): Promise<RagDoc[]>;
|
|
24
|
+
export declare function ragChunk(params: RagChunkParams, options?: RPCOptions): Promise<RagDoc[]>;
|
|
25
25
|
/**
|
|
26
26
|
* Ingests documents into the RAG vector database.
|
|
27
27
|
* Full pipeline: chunk → embed → save
|
|
@@ -60,7 +60,7 @@ export declare function ragChunk(params: RagChunkParams): Promise<RagDoc[]>;
|
|
|
60
60
|
* });
|
|
61
61
|
* ```
|
|
62
62
|
*/
|
|
63
|
-
export declare function ragIngest(params: RagIngestParams): Promise<{
|
|
63
|
+
export declare function ragIngest(params: RagIngestParams, options?: RPCOptions): Promise<{
|
|
64
64
|
processed: RagSaveEmbeddingsResult[];
|
|
65
65
|
droppedIndices: number[];
|
|
66
66
|
}>;
|
|
@@ -96,7 +96,7 @@ export declare function ragIngest(params: RagIngestParams): Promise<{
|
|
|
96
96
|
* });
|
|
97
97
|
* ```
|
|
98
98
|
*/
|
|
99
|
-
export declare function ragSaveEmbeddings(params: RagSaveEmbeddingsParams): Promise<RagSaveEmbeddingsResult[]>;
|
|
99
|
+
export declare function ragSaveEmbeddings(params: RagSaveEmbeddingsParams, options?: RPCOptions): Promise<RagSaveEmbeddingsResult[]>;
|
|
100
100
|
/**
|
|
101
101
|
* Searches for similar documents in the RAG vector database.
|
|
102
102
|
*
|
|
@@ -122,7 +122,7 @@ export declare function ragSaveEmbeddings(params: RagSaveEmbeddingsParams): Prom
|
|
|
122
122
|
* });
|
|
123
123
|
* ```
|
|
124
124
|
*/
|
|
125
|
-
export declare function ragSearch(params: RagSearchParams): Promise<RagSearchResult[]>;
|
|
125
|
+
export declare function ragSearch(params: RagSearchParams, options?: RPCOptions): Promise<RagSearchResult[]>;
|
|
126
126
|
/**
|
|
127
127
|
* Deletes document embeddings from the RAG vector database.
|
|
128
128
|
*
|
|
@@ -141,7 +141,7 @@ export declare function ragSearch(params: RagSearchParams): Promise<RagSearchRes
|
|
|
141
141
|
* });
|
|
142
142
|
* ```
|
|
143
143
|
*/
|
|
144
|
-
export declare function ragDeleteEmbeddings(params: RagDeleteEmbeddingsParams): Promise<void>;
|
|
144
|
+
export declare function ragDeleteEmbeddings(params: RagDeleteEmbeddingsParams, options?: RPCOptions): Promise<void>;
|
|
145
145
|
/**
|
|
146
146
|
* Reindexes the RAG database to optimize search performance.
|
|
147
147
|
* For HyperDB, this rebalances centroids using k-means clustering.
|
|
@@ -180,7 +180,7 @@ export declare function ragDeleteEmbeddings(params: RagDeleteEmbeddingsParams):
|
|
|
180
180
|
* });
|
|
181
181
|
* ```
|
|
182
182
|
*/
|
|
183
|
-
export declare function ragReindex(params: RagReindexParams): Promise<RagReindexResult>;
|
|
183
|
+
export declare function ragReindex(params: RagReindexParams, options?: RPCOptions): Promise<RagReindexResult>;
|
|
184
184
|
/**
|
|
185
185
|
* Lists all RAG workspaces with their open status.
|
|
186
186
|
*
|
|
@@ -197,7 +197,7 @@ export declare function ragReindex(params: RagReindexParams): Promise<RagReindex
|
|
|
197
197
|
* // [{ name: "default", open: true }, { name: "my-docs", open: false }]
|
|
198
198
|
* ```
|
|
199
199
|
*/
|
|
200
|
-
export declare function ragListWorkspaces(): Promise<RagWorkspaceInfo[]>;
|
|
200
|
+
export declare function ragListWorkspaces(options?: RPCOptions): Promise<RagWorkspaceInfo[]>;
|
|
201
201
|
/**
|
|
202
202
|
* Closes a RAG workspace, releasing in-memory resources (Corestore, HyperDB adapter, RAG instance).
|
|
203
203
|
*
|
|
@@ -219,7 +219,7 @@ export declare function ragListWorkspaces(): Promise<RagWorkspaceInfo[]>;
|
|
|
219
219
|
* await ragCloseWorkspace({ workspace: "my-docs", deleteOnClose: true });
|
|
220
220
|
* ```
|
|
221
221
|
*/
|
|
222
|
-
export declare function ragCloseWorkspace(params?: RagCloseWorkspaceParams): Promise<void>;
|
|
222
|
+
export declare function ragCloseWorkspace(params?: RagCloseWorkspaceParams, options?: RPCOptions): Promise<void>;
|
|
223
223
|
/**
|
|
224
224
|
* Deletes a RAG workspace and all its data.
|
|
225
225
|
* The workspace must not be currently loaded/in-use.
|
|
@@ -233,5 +233,5 @@ export declare function ragCloseWorkspace(params?: RagCloseWorkspaceParams): Pro
|
|
|
233
233
|
* await ragDeleteWorkspace({ workspace: "my-docs" });
|
|
234
234
|
* ```
|
|
235
235
|
*/
|
|
236
|
-
export declare function ragDeleteWorkspace(params: RagDeleteWorkspaceParams): Promise<void>;
|
|
236
|
+
export declare function ragDeleteWorkspace(params: RagDeleteWorkspaceParams, options?: RPCOptions): Promise<void>;
|
|
237
237
|
//# sourceMappingURL=rag.d.ts.map
|
package/dist/client/api/rag.js
CHANGED
|
@@ -23,13 +23,13 @@ import { InvalidResponseError, InvalidOperationError, StreamEndedError, RAGChunk
|
|
|
23
23
|
* });
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
|
-
export async function ragChunk(params) {
|
|
26
|
+
export async function ragChunk(params, options) {
|
|
27
27
|
const request = {
|
|
28
28
|
type: "rag",
|
|
29
29
|
operation: "chunk",
|
|
30
30
|
...params,
|
|
31
31
|
};
|
|
32
|
-
const response = await send(request);
|
|
32
|
+
const response = await send(request, options);
|
|
33
33
|
if (response.type !== "rag") {
|
|
34
34
|
throw new InvalidResponseError("rag");
|
|
35
35
|
}
|
|
@@ -80,7 +80,7 @@ export async function ragChunk(params) {
|
|
|
80
80
|
* });
|
|
81
81
|
* ```
|
|
82
82
|
*/
|
|
83
|
-
export async function ragIngest(params) {
|
|
83
|
+
export async function ragIngest(params, options) {
|
|
84
84
|
const { onProgress, ...requestParams } = params;
|
|
85
85
|
const request = {
|
|
86
86
|
type: "rag",
|
|
@@ -91,7 +91,7 @@ export async function ragIngest(params) {
|
|
|
91
91
|
};
|
|
92
92
|
if (onProgress) {
|
|
93
93
|
// Use streaming for progress updates
|
|
94
|
-
for await (const event of stream(request)) {
|
|
94
|
+
for await (const event of stream(request, options)) {
|
|
95
95
|
if (event.type === "rag:progress" && event.operation === "ingest") {
|
|
96
96
|
const progress = event;
|
|
97
97
|
onProgress(progress.stage, progress.current, progress.total);
|
|
@@ -109,7 +109,7 @@ export async function ragIngest(params) {
|
|
|
109
109
|
}
|
|
110
110
|
throw new StreamEndedError();
|
|
111
111
|
}
|
|
112
|
-
const response = await send(request);
|
|
112
|
+
const response = await send(request, options);
|
|
113
113
|
if (response.type !== "rag") {
|
|
114
114
|
throw new InvalidResponseError("rag");
|
|
115
115
|
}
|
|
@@ -157,7 +157,7 @@ export async function ragIngest(params) {
|
|
|
157
157
|
* });
|
|
158
158
|
* ```
|
|
159
159
|
*/
|
|
160
|
-
export async function ragSaveEmbeddings(params) {
|
|
160
|
+
export async function ragSaveEmbeddings(params, options) {
|
|
161
161
|
const { onProgress, ...requestParams } = params;
|
|
162
162
|
const request = {
|
|
163
163
|
type: "rag",
|
|
@@ -166,7 +166,7 @@ export async function ragSaveEmbeddings(params) {
|
|
|
166
166
|
withProgress: onProgress ? true : undefined,
|
|
167
167
|
};
|
|
168
168
|
if (onProgress) {
|
|
169
|
-
for await (const event of stream(request)) {
|
|
169
|
+
for await (const event of stream(request, options)) {
|
|
170
170
|
if (event.type === "rag:progress" &&
|
|
171
171
|
event.operation === "saveEmbeddings") {
|
|
172
172
|
const progress = event;
|
|
@@ -182,7 +182,7 @@ export async function ragSaveEmbeddings(params) {
|
|
|
182
182
|
}
|
|
183
183
|
throw new StreamEndedError();
|
|
184
184
|
}
|
|
185
|
-
const response = await send(request);
|
|
185
|
+
const response = await send(request, options);
|
|
186
186
|
if (response.type !== "rag") {
|
|
187
187
|
throw new InvalidResponseError("rag");
|
|
188
188
|
}
|
|
@@ -220,7 +220,7 @@ export async function ragSaveEmbeddings(params) {
|
|
|
220
220
|
* });
|
|
221
221
|
* ```
|
|
222
222
|
*/
|
|
223
|
-
export async function ragSearch(params) {
|
|
223
|
+
export async function ragSearch(params, options) {
|
|
224
224
|
const request = {
|
|
225
225
|
type: "rag",
|
|
226
226
|
operation: "search",
|
|
@@ -228,7 +228,7 @@ export async function ragSearch(params) {
|
|
|
228
228
|
topK: params.topK ?? 5,
|
|
229
229
|
n: params.n ?? 3,
|
|
230
230
|
};
|
|
231
|
-
const response = await send(request);
|
|
231
|
+
const response = await send(request, options);
|
|
232
232
|
if (response.type !== "rag") {
|
|
233
233
|
throw new InvalidResponseError("rag");
|
|
234
234
|
}
|
|
@@ -259,13 +259,13 @@ export async function ragSearch(params) {
|
|
|
259
259
|
* });
|
|
260
260
|
* ```
|
|
261
261
|
*/
|
|
262
|
-
export async function ragDeleteEmbeddings(params) {
|
|
262
|
+
export async function ragDeleteEmbeddings(params, options) {
|
|
263
263
|
const request = {
|
|
264
264
|
type: "rag",
|
|
265
265
|
operation: "deleteEmbeddings",
|
|
266
266
|
...params,
|
|
267
267
|
};
|
|
268
|
-
const response = await send(request);
|
|
268
|
+
const response = await send(request, options);
|
|
269
269
|
if (response.type !== "rag") {
|
|
270
270
|
throw new InvalidResponseError("rag");
|
|
271
271
|
}
|
|
@@ -315,7 +315,7 @@ export async function ragDeleteEmbeddings(params) {
|
|
|
315
315
|
* });
|
|
316
316
|
* ```
|
|
317
317
|
*/
|
|
318
|
-
export async function ragReindex(params) {
|
|
318
|
+
export async function ragReindex(params, options) {
|
|
319
319
|
const { onProgress, ...requestParams } = params;
|
|
320
320
|
const request = {
|
|
321
321
|
type: "rag",
|
|
@@ -324,7 +324,7 @@ export async function ragReindex(params) {
|
|
|
324
324
|
withProgress: onProgress ? true : undefined,
|
|
325
325
|
};
|
|
326
326
|
if (onProgress) {
|
|
327
|
-
for await (const event of stream(request)) {
|
|
327
|
+
for await (const event of stream(request, options)) {
|
|
328
328
|
if (event.type === "rag:progress" && event.operation === "reindex") {
|
|
329
329
|
const progress = event;
|
|
330
330
|
onProgress(progress.stage, progress.current, progress.total);
|
|
@@ -339,7 +339,7 @@ export async function ragReindex(params) {
|
|
|
339
339
|
}
|
|
340
340
|
throw new StreamEndedError();
|
|
341
341
|
}
|
|
342
|
-
const response = await send(request);
|
|
342
|
+
const response = await send(request, options);
|
|
343
343
|
if (response.type !== "rag") {
|
|
344
344
|
throw new InvalidResponseError("rag");
|
|
345
345
|
}
|
|
@@ -368,12 +368,12 @@ export async function ragReindex(params) {
|
|
|
368
368
|
* // [{ name: "default", open: true }, { name: "my-docs", open: false }]
|
|
369
369
|
* ```
|
|
370
370
|
*/
|
|
371
|
-
export async function ragListWorkspaces() {
|
|
371
|
+
export async function ragListWorkspaces(options) {
|
|
372
372
|
const request = {
|
|
373
373
|
type: "rag",
|
|
374
374
|
operation: "listWorkspaces",
|
|
375
375
|
};
|
|
376
|
-
const response = await send(request);
|
|
376
|
+
const response = await send(request, options);
|
|
377
377
|
if (response.type !== "rag") {
|
|
378
378
|
throw new InvalidResponseError("rag");
|
|
379
379
|
}
|
|
@@ -407,13 +407,13 @@ export async function ragListWorkspaces() {
|
|
|
407
407
|
* await ragCloseWorkspace({ workspace: "my-docs", deleteOnClose: true });
|
|
408
408
|
* ```
|
|
409
409
|
*/
|
|
410
|
-
export async function ragCloseWorkspace(params) {
|
|
410
|
+
export async function ragCloseWorkspace(params, options) {
|
|
411
411
|
const request = {
|
|
412
412
|
type: "rag",
|
|
413
413
|
operation: "closeWorkspace",
|
|
414
414
|
...params,
|
|
415
415
|
};
|
|
416
|
-
const response = await send(request);
|
|
416
|
+
const response = await send(request, options);
|
|
417
417
|
if (response.type !== "rag") {
|
|
418
418
|
throw new InvalidResponseError("rag");
|
|
419
419
|
}
|
|
@@ -438,13 +438,13 @@ export async function ragCloseWorkspace(params) {
|
|
|
438
438
|
* await ragDeleteWorkspace({ workspace: "my-docs" });
|
|
439
439
|
* ```
|
|
440
440
|
*/
|
|
441
|
-
export async function ragDeleteWorkspace(params) {
|
|
441
|
+
export async function ragDeleteWorkspace(params, options) {
|
|
442
442
|
const request = {
|
|
443
443
|
type: "rag",
|
|
444
444
|
operation: "deleteWorkspace",
|
|
445
445
|
...params,
|
|
446
446
|
};
|
|
447
|
-
const response = await send(request);
|
|
447
|
+
const response = await send(request, options);
|
|
448
448
|
if (response.type !== "rag") {
|
|
449
449
|
throw new InvalidResponseError("rag");
|
|
450
450
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type TtsClientParams } from "../../schemas/index";
|
|
2
|
-
export declare function textToSpeech(params: TtsClientParams): {
|
|
1
|
+
import { type TtsClientParams, type RPCOptions } from "../../schemas/index";
|
|
2
|
+
export declare function textToSpeech(params: TtsClientParams, options?: RPCOptions): {
|
|
3
3
|
bufferStream: AsyncGenerator<number>;
|
|
4
4
|
buffer: Promise<number[]>;
|
|
5
5
|
done: Promise<boolean>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ttsResponseSchema, } from "../../schemas/index.js";
|
|
2
2
|
import { stream as streamRpc } from "../rpc/rpc-client.js";
|
|
3
|
-
export function textToSpeech(params) {
|
|
3
|
+
export function textToSpeech(params, options) {
|
|
4
4
|
const request = {
|
|
5
5
|
type: "textToSpeech",
|
|
6
6
|
modelId: params.modelId,
|
|
@@ -14,7 +14,7 @@ export function textToSpeech(params) {
|
|
|
14
14
|
});
|
|
15
15
|
if (params.stream) {
|
|
16
16
|
const bufferStream = (async function* () {
|
|
17
|
-
for await (const response of streamRpc(request)) {
|
|
17
|
+
for await (const response of streamRpc(request, options)) {
|
|
18
18
|
if (response.type === "textToSpeech") {
|
|
19
19
|
const streamResponse = ttsResponseSchema.parse(response);
|
|
20
20
|
if (streamResponse.buffer.length > 0) {
|
|
@@ -38,7 +38,7 @@ export function textToSpeech(params) {
|
|
|
38
38
|
})();
|
|
39
39
|
const bufferPromise = (async () => {
|
|
40
40
|
let buffer = [];
|
|
41
|
-
for await (const response of streamRpc(request)) {
|
|
41
|
+
for await (const response of streamRpc(request, options)) {
|
|
42
42
|
if (response.type === "textToSpeech") {
|
|
43
43
|
const streamResponse = ttsResponseSchema.parse(response);
|
|
44
44
|
buffer = buffer.concat(streamResponse.buffer);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type TranscribeClientParams } from "../../schemas/index";
|
|
1
|
+
import { type TranscribeClientParams, type RPCOptions } from "../../schemas/index";
|
|
2
2
|
/**
|
|
3
3
|
* This function streams audio transcription results in real-time, yielding
|
|
4
4
|
* text chunks as they become available from the model.
|
|
@@ -7,10 +7,11 @@ import { type TranscribeClientParams } from "../../schemas/index";
|
|
|
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
9
|
* @param params.prompt - Optional initial prompt to guide the transcription
|
|
10
|
+
* @param options - Optional RPC options including per-call profiling
|
|
10
11
|
* @yields {string} Text chunks as they are transcribed
|
|
11
12
|
* @throws {QvacErrorBase} When transcription fails with an error message
|
|
12
13
|
*/
|
|
13
|
-
export declare function transcribeStream(params: TranscribeClientParams): AsyncGenerator<string, void, unknown>;
|
|
14
|
+
export declare function transcribeStream(params: TranscribeClientParams, options?: RPCOptions): AsyncGenerator<string, void, unknown>;
|
|
14
15
|
/**
|
|
15
16
|
* This function provides a simple interface for transcribing audio by
|
|
16
17
|
* collecting all streaming results into a single string response.
|
|
@@ -19,8 +20,9 @@ export declare function transcribeStream(params: TranscribeClientParams): AsyncG
|
|
|
19
20
|
* @param params.modelId - The identifier of the transcription model to use
|
|
20
21
|
* @param params.audioChunk - Audio input as either a file path (string) or audio buffer
|
|
21
22
|
* @param params.prompt - Optional initial prompt to guide the transcription
|
|
23
|
+
* @param options - Optional RPC options including per-call profiling
|
|
22
24
|
* @returns {Promise<string>} The complete transcribed text
|
|
23
25
|
* @throws {QvacErrorBase} When transcription fails (propagated from transcribeStream)
|
|
24
26
|
*/
|
|
25
|
-
export declare function transcribe(params: TranscribeClientParams): Promise<string>;
|
|
27
|
+
export declare function transcribe(params: TranscribeClientParams, options?: RPCOptions): Promise<string>;
|
|
26
28
|
//# sourceMappingURL=transcribe.d.ts.map
|
|
@@ -8,10 +8,11 @@ import { stream } from "../rpc/rpc-client.js";
|
|
|
8
8
|
* @param params.modelId - The identifier of the transcription model to use
|
|
9
9
|
* @param params.audioChunk - Audio input as either a file path (string) or audio buffer
|
|
10
10
|
* @param params.prompt - Optional initial prompt to guide the transcription
|
|
11
|
+
* @param options - Optional RPC options including per-call profiling
|
|
11
12
|
* @yields {string} Text chunks as they are transcribed
|
|
12
13
|
* @throws {QvacErrorBase} When transcription fails with an error message
|
|
13
14
|
*/
|
|
14
|
-
export async function* transcribeStream(params) {
|
|
15
|
+
export async function* transcribeStream(params, options) {
|
|
15
16
|
const request = {
|
|
16
17
|
type: "transcribeStream",
|
|
17
18
|
modelId: params.modelId,
|
|
@@ -20,7 +21,7 @@ export async function* transcribeStream(params) {
|
|
|
20
21
|
: { type: "base64", value: params.audioChunk.toString("base64") },
|
|
21
22
|
...(params.prompt && { prompt: params.prompt }),
|
|
22
23
|
};
|
|
23
|
-
for await (const response of stream(request)) {
|
|
24
|
+
for await (const response of stream(request, options)) {
|
|
24
25
|
if (response.type === "transcribeStream") {
|
|
25
26
|
const streamResponse = transcribeStreamResponseSchema.parse(response);
|
|
26
27
|
if (streamResponse.text) {
|
|
@@ -40,12 +41,13 @@ export async function* transcribeStream(params) {
|
|
|
40
41
|
* @param params.modelId - The identifier of the transcription model to use
|
|
41
42
|
* @param params.audioChunk - Audio input as either a file path (string) or audio buffer
|
|
42
43
|
* @param params.prompt - Optional initial prompt to guide the transcription
|
|
44
|
+
* @param options - Optional RPC options including per-call profiling
|
|
43
45
|
* @returns {Promise<string>} The complete transcribed text
|
|
44
46
|
* @throws {QvacErrorBase} When transcription fails (propagated from transcribeStream)
|
|
45
47
|
*/
|
|
46
|
-
export async function transcribe(params) {
|
|
48
|
+
export async function transcribe(params, options) {
|
|
47
49
|
let fullText = "";
|
|
48
|
-
for await (const textChunk of transcribeStream(params)) {
|
|
50
|
+
for await (const textChunk of transcribeStream(params, options)) {
|
|
49
51
|
fullText += textChunk;
|
|
50
52
|
}
|
|
51
53
|
return fullText;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type TranslateClientParams, type TranslationStats } from "../../schemas/index";
|
|
1
|
+
import { type TranslateClientParams, type TranslationStats, type RPCOptions } from "../../schemas/index";
|
|
2
2
|
/**
|
|
3
3
|
* Translates text from one language to another using a specified translation model.
|
|
4
4
|
* Supports both NMT (Neural Machine Translation) and LLM models.
|
|
@@ -39,7 +39,7 @@ import { type TranslateClientParams, type TranslationStats } from "../../schemas
|
|
|
39
39
|
* console.log(await response.text);
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
|
-
export declare function translate(params: TranslateClientParams): {
|
|
42
|
+
export declare function translate(params: TranslateClientParams, options?: RPCOptions): {
|
|
43
43
|
tokenStream: AsyncGenerator<string>;
|
|
44
44
|
stats: Promise<TranslationStats | undefined>;
|
|
45
45
|
text: Promise<string>;
|
|
@@ -42,7 +42,7 @@ import { TranslationFailedError } from "../../utils/errors-client.js";
|
|
|
42
42
|
* console.log(await response.text);
|
|
43
43
|
* ```
|
|
44
44
|
*/
|
|
45
|
-
export function translate(params) {
|
|
45
|
+
export function translate(params, options) {
|
|
46
46
|
const canonicalModelType = normalizeModelType(params.modelType);
|
|
47
47
|
const isLlm = canonicalModelType === ModelType.llamacppCompletion;
|
|
48
48
|
let sourceLanguage = isLlm ? params.from : undefined;
|
|
@@ -67,7 +67,7 @@ export function translate(params) {
|
|
|
67
67
|
});
|
|
68
68
|
if (params.stream) {
|
|
69
69
|
const tokenStream = (async function* () {
|
|
70
|
-
for await (const response of streamRpc(request)) {
|
|
70
|
+
for await (const response of streamRpc(request, options)) {
|
|
71
71
|
if (response.type === "translate") {
|
|
72
72
|
const streamResponse = translateResponseSchema.parse(response);
|
|
73
73
|
if (!streamResponse.done) {
|
|
@@ -93,7 +93,7 @@ export function translate(params) {
|
|
|
93
93
|
})();
|
|
94
94
|
const textPromise = (async () => {
|
|
95
95
|
let buffer = "";
|
|
96
|
-
for await (const response of streamRpc(request)) {
|
|
96
|
+
for await (const response of streamRpc(request, options)) {
|
|
97
97
|
if (response.type === "translate") {
|
|
98
98
|
const streamResponse = translateResponseSchema.parse(response);
|
|
99
99
|
buffer += streamResponse.token;
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
send: (data: string, encoding: BufferEncoding) => void;
|
|
4
|
-
reply: (encoding: BufferEncoding) => Promise<Buffer>;
|
|
5
|
-
createResponseStream: () => AsyncGenerator<unknown, void, unknown>;
|
|
6
|
-
};
|
|
7
|
-
};
|
|
1
|
+
import RPC from "bare-rpc";
|
|
2
|
+
export declare function getRPC(): Promise<RPC>;
|
|
8
3
|
export declare function close(): Promise<void>;
|
|
9
4
|
//# sourceMappingURL=node-rpc-client.d.ts.map
|
|
@@ -7,7 +7,6 @@ import fs from "node:fs";
|
|
|
7
7
|
import os from "node:os";
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
|
-
import { RPCRequestNotSentError } from "../../utils/errors-client.js";
|
|
11
10
|
import { initializeConfig } from "../init-hooks.js";
|
|
12
11
|
import { resolveConfig } from "../config-loader/resolve-config.node.js";
|
|
13
12
|
import { getClientLogger } from "../../logging/index.js";
|
|
@@ -202,44 +201,8 @@ async function ensureRPC() {
|
|
|
202
201
|
await initializeConfig(rpc, resolveConfig, runtimeContext);
|
|
203
202
|
return rpc;
|
|
204
203
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
let sentData = null;
|
|
208
|
-
return {
|
|
209
|
-
send: (data, encoding) => {
|
|
210
|
-
sentData = { data, encoding };
|
|
211
|
-
},
|
|
212
|
-
reply: async (encoding) => {
|
|
213
|
-
if (!sentData) {
|
|
214
|
-
throw new RPCRequestNotSentError();
|
|
215
|
-
}
|
|
216
|
-
const rpc = await ensureRPC();
|
|
217
|
-
const req = rpc.request(command);
|
|
218
|
-
req.send(sentData.data, sentData.encoding);
|
|
219
|
-
const response = await req.reply(encoding);
|
|
220
|
-
return Buffer.isBuffer(response)
|
|
221
|
-
? response
|
|
222
|
-
: Buffer.from(typeof response === "string" ? response : "", encoding);
|
|
223
|
-
},
|
|
224
|
-
createResponseStream: async function* () {
|
|
225
|
-
if (!sentData) {
|
|
226
|
-
throw new RPCRequestNotSentError();
|
|
227
|
-
}
|
|
228
|
-
const rpc = await ensureRPC();
|
|
229
|
-
const req = rpc.request(command);
|
|
230
|
-
req.send(sentData.data, sentData.encoding);
|
|
231
|
-
const stream = req.createResponseStream({
|
|
232
|
-
encoding: sentData.encoding,
|
|
233
|
-
});
|
|
234
|
-
for await (const chunk of stream) {
|
|
235
|
-
yield chunk;
|
|
236
|
-
}
|
|
237
|
-
},
|
|
238
|
-
};
|
|
239
|
-
},
|
|
240
|
-
};
|
|
241
|
-
export function getRPC() {
|
|
242
|
-
return mockRPC;
|
|
204
|
+
export async function getRPC() {
|
|
205
|
+
return ensureRPC();
|
|
243
206
|
}
|
|
244
207
|
export async function close() {
|
|
245
208
|
if (closePromise) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./profiler.js";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type BaseTimings } from "../../../profiling/index";
|
|
2
|
+
import type { ProfilingResponseMeta } from "../../../schemas/index";
|
|
3
|
+
interface BaseClientTimings extends BaseTimings {
|
|
4
|
+
requestZodValidationMs?: number;
|
|
5
|
+
requestStringifyMs?: number;
|
|
6
|
+
sendStart?: number;
|
|
7
|
+
requestEnd?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface ClientTimings extends BaseClientTimings {
|
|
10
|
+
firstResponseAt?: number;
|
|
11
|
+
responseJsonParseMs?: number;
|
|
12
|
+
responseZodValidationMs?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ClientStreamTimings extends BaseClientTimings {
|
|
15
|
+
firstChunkAt?: number;
|
|
16
|
+
lastChunkAt?: number;
|
|
17
|
+
chunkCount: number;
|
|
18
|
+
}
|
|
19
|
+
export declare function createClientTimings(profileId: string, requestType: string): ClientTimings;
|
|
20
|
+
export declare function createClientStreamTimings(profileId: string, requestType: string): ClientStreamTimings;
|
|
21
|
+
export declare function cacheConnectionTime(durationMs: number): void;
|
|
22
|
+
export declare function flushConnectionTime(): void;
|
|
23
|
+
export declare function recordClientEvents(timings: ClientTimings, serverMeta?: ProfilingResponseMeta): void;
|
|
24
|
+
export declare function recordClientStreamEvents(timings: ClientStreamTimings, serverMeta?: ProfilingResponseMeta): void;
|
|
25
|
+
export declare function resetConnectionTracking(): void;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=profiler.d.ts.map
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { nowMs, record, recordPhase, recordServerBreakdownPhases, recordDelegationBreakdownPhases, } from "../../../profiling/index.js";
|
|
2
|
+
import { getGlobalSingleton } from "../../../utils/global-singleton.js";
|
|
3
|
+
const CONNECTION_TRACKING_STATE_KEY = Symbol.for("@qvac/sdk:rpc-connection-tracking-state");
|
|
4
|
+
function getConnectionTrackingState() {
|
|
5
|
+
return getGlobalSingleton(CONNECTION_TRACKING_STATE_KEY, () => {
|
|
6
|
+
return {
|
|
7
|
+
connectionTimeRecorded: false,
|
|
8
|
+
pendingConnectionTimeMs: undefined,
|
|
9
|
+
};
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
function recordRequestPhases(base, timings) {
|
|
13
|
+
recordPhase(base, "request.zodValidation", timings.requestZodValidationMs);
|
|
14
|
+
recordPhase(base, "request.stringify", timings.requestStringifyMs);
|
|
15
|
+
if (timings.requestZodValidationMs !== undefined &&
|
|
16
|
+
timings.requestStringifyMs !== undefined) {
|
|
17
|
+
recordPhase(base, "request.totalSerialization", timings.requestZodValidationMs + timings.requestStringifyMs);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function createBaseTimings(profileId, requestType) {
|
|
21
|
+
return { profileId, requestType, requestStart: nowMs() };
|
|
22
|
+
}
|
|
23
|
+
export function createClientTimings(profileId, requestType) {
|
|
24
|
+
return createBaseTimings(profileId, requestType);
|
|
25
|
+
}
|
|
26
|
+
export function createClientStreamTimings(profileId, requestType) {
|
|
27
|
+
return { ...createBaseTimings(profileId, requestType), chunkCount: 0 };
|
|
28
|
+
}
|
|
29
|
+
export function cacheConnectionTime(durationMs) {
|
|
30
|
+
const state = getConnectionTrackingState();
|
|
31
|
+
if (state.connectionTimeRecorded)
|
|
32
|
+
return;
|
|
33
|
+
if (state.pendingConnectionTimeMs !== undefined)
|
|
34
|
+
return;
|
|
35
|
+
state.pendingConnectionTimeMs = durationMs;
|
|
36
|
+
}
|
|
37
|
+
export function flushConnectionTime() {
|
|
38
|
+
const state = getConnectionTrackingState();
|
|
39
|
+
if (state.connectionTimeRecorded)
|
|
40
|
+
return;
|
|
41
|
+
if (state.pendingConnectionTimeMs === undefined)
|
|
42
|
+
return;
|
|
43
|
+
const durationMs = state.pendingConnectionTimeMs;
|
|
44
|
+
state.pendingConnectionTimeMs = undefined;
|
|
45
|
+
state.connectionTimeRecorded = true;
|
|
46
|
+
record({
|
|
47
|
+
ts: nowMs(),
|
|
48
|
+
op: "rpc",
|
|
49
|
+
kind: "rpc",
|
|
50
|
+
phase: "connection",
|
|
51
|
+
ms: durationMs,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
export function recordClientEvents(timings, serverMeta) {
|
|
55
|
+
const now = nowMs();
|
|
56
|
+
const totalClientTime = now - timings.requestStart;
|
|
57
|
+
const base = {
|
|
58
|
+
ts: now,
|
|
59
|
+
op: timings.requestType,
|
|
60
|
+
kind: "rpc",
|
|
61
|
+
profileId: timings.profileId,
|
|
62
|
+
};
|
|
63
|
+
recordRequestPhases(base, timings);
|
|
64
|
+
// For unary requests, this measures send → full response received
|
|
65
|
+
if (timings.sendStart !== undefined &&
|
|
66
|
+
timings.firstResponseAt !== undefined) {
|
|
67
|
+
recordPhase(base, "serverWait", timings.firstResponseAt - timings.sendStart);
|
|
68
|
+
}
|
|
69
|
+
recordPhase(base, "response.jsonParse", timings.responseJsonParseMs);
|
|
70
|
+
recordPhase(base, "response.zodValidation", timings.responseZodValidationMs);
|
|
71
|
+
if (timings.responseJsonParseMs !== undefined &&
|
|
72
|
+
timings.responseZodValidationMs !== undefined) {
|
|
73
|
+
recordPhase(base, "response.totalParsing", timings.responseJsonParseMs + timings.responseZodValidationMs);
|
|
74
|
+
}
|
|
75
|
+
recordPhase(base, "totalClientTime", totalClientTime);
|
|
76
|
+
if (serverMeta?.server) {
|
|
77
|
+
recordServerBreakdownPhases(base, serverMeta.server, "server");
|
|
78
|
+
if (serverMeta.server.totalServerMs !== undefined) {
|
|
79
|
+
recordPhase(base, "clientOverhead", Math.max(0, totalClientTime - serverMeta.server.totalServerMs));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (serverMeta?.delegation) {
|
|
83
|
+
recordDelegationBreakdownPhases(base, serverMeta.delegation);
|
|
84
|
+
}
|
|
85
|
+
if (serverMeta?.operation) {
|
|
86
|
+
recordOperationEvent(serverMeta.operation);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function recordOperationEvent(op) {
|
|
90
|
+
const event = {
|
|
91
|
+
ts: nowMs(),
|
|
92
|
+
op: op.op,
|
|
93
|
+
kind: op.kind,
|
|
94
|
+
ms: op.ms,
|
|
95
|
+
};
|
|
96
|
+
if (op.profileId !== undefined)
|
|
97
|
+
event.profileId = op.profileId;
|
|
98
|
+
if (op.gauges !== undefined)
|
|
99
|
+
event.gauges = op.gauges;
|
|
100
|
+
if (op.tags !== undefined)
|
|
101
|
+
event.tags = op.tags;
|
|
102
|
+
if (op.count !== undefined)
|
|
103
|
+
event.count = op.count;
|
|
104
|
+
record(event);
|
|
105
|
+
}
|
|
106
|
+
export function recordClientStreamEvents(timings, serverMeta) {
|
|
107
|
+
const now = nowMs();
|
|
108
|
+
const totalClientTime = now - timings.requestStart;
|
|
109
|
+
const base = {
|
|
110
|
+
ts: now,
|
|
111
|
+
op: timings.requestType,
|
|
112
|
+
kind: "rpc",
|
|
113
|
+
profileId: timings.profileId,
|
|
114
|
+
};
|
|
115
|
+
recordRequestPhases(base, timings);
|
|
116
|
+
if (timings.sendStart !== undefined && timings.firstChunkAt !== undefined) {
|
|
117
|
+
recordPhase(base, "ttfb", timings.firstChunkAt - timings.sendStart);
|
|
118
|
+
}
|
|
119
|
+
if (timings.firstChunkAt !== undefined && timings.lastChunkAt !== undefined) {
|
|
120
|
+
recordPhase(base, "streamDuration", timings.lastChunkAt - timings.firstChunkAt);
|
|
121
|
+
}
|
|
122
|
+
recordPhase(base, "totalClientTime", totalClientTime, {
|
|
123
|
+
count: timings.chunkCount,
|
|
124
|
+
});
|
|
125
|
+
if (serverMeta?.server) {
|
|
126
|
+
recordServerBreakdownPhases(base, serverMeta.server, "server");
|
|
127
|
+
}
|
|
128
|
+
if (serverMeta?.delegation) {
|
|
129
|
+
recordDelegationBreakdownPhases(base, serverMeta.delegation);
|
|
130
|
+
}
|
|
131
|
+
if (serverMeta?.operation) {
|
|
132
|
+
recordOperationEvent(serverMeta.operation);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
export function resetConnectionTracking() {
|
|
136
|
+
const state = getConnectionTrackingState();
|
|
137
|
+
state.connectionTimeRecorded = false;
|
|
138
|
+
state.pendingConnectionTimeMs = undefined;
|
|
139
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type RPC from "bare-rpc";
|
|
2
2
|
import { type Request, type Response, type RPCOptions } from "../../schemas/index";
|
|
3
|
-
export declare function send<T extends Request>(request: T,
|
|
4
|
-
export declare function stream<T extends Request>(request: T,
|
|
3
|
+
export declare function send<T extends Request>(request: T, options?: RPCOptions, rpc?: RPC): Promise<Response>;
|
|
4
|
+
export declare function stream<T extends Request>(request: T, options?: RPCOptions, rpc?: RPC): AsyncGenerator<Response>;
|
|
5
5
|
export declare function close(): Promise<void>;
|
|
6
6
|
//# sourceMappingURL=rpc-client.d.ts.map
|