@qvac/sdk 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/NOTICE +57 -331
  2. package/README.md +2 -2
  3. package/bare-imports.json +9 -0
  4. package/dist/client/api/completion-stream.d.ts +2 -1
  5. package/dist/client/api/completion-stream.js +2 -1
  6. package/dist/client/api/download-asset.d.ts +3 -2
  7. package/dist/client/api/download-asset.js +4 -3
  8. package/dist/client/api/embed.d.ts +5 -2
  9. package/dist/client/api/embed.js +2 -2
  10. package/dist/client/api/get-model-info.d.ts +1 -1
  11. package/dist/client/api/invoke-plugin.d.ts +3 -2
  12. package/dist/client/api/invoke-plugin.js +4 -4
  13. package/dist/client/api/load-model.d.ts +12 -10
  14. package/dist/client/api/load-model.js +3 -3
  15. package/dist/client/api/rag.d.ts +10 -10
  16. package/dist/client/api/rag.js +21 -21
  17. package/dist/client/api/text-to-speech.d.ts +2 -2
  18. package/dist/client/api/text-to-speech.js +3 -3
  19. package/dist/client/api/transcribe.d.ts +5 -3
  20. package/dist/client/api/transcribe.js +6 -4
  21. package/dist/client/api/translate.d.ts +2 -2
  22. package/dist/client/api/translate.js +3 -3
  23. package/dist/client/rpc/node-rpc-client.d.ts +2 -7
  24. package/dist/client/rpc/node-rpc-client.js +2 -39
  25. package/dist/client/rpc/profiling/index.d.ts +2 -0
  26. package/dist/client/rpc/profiling/index.js +1 -0
  27. package/dist/client/rpc/profiling/profiler.d.ts +27 -0
  28. package/dist/client/rpc/profiling/profiler.js +139 -0
  29. package/dist/client/rpc/rpc-client.d.ts +2 -2
  30. package/dist/client/rpc/rpc-client.js +174 -12
  31. package/dist/examples/delegated-inference/consumer-profiled.d.ts +2 -0
  32. package/dist/examples/delegated-inference/consumer-profiled.js +67 -0
  33. package/dist/examples/llamacpp-multimodal.js +1 -1
  34. package/dist/examples/parallel-download.js +45 -13
  35. package/dist/examples/profiling/basic.d.ts +2 -0
  36. package/dist/examples/profiling/basic.js +71 -0
  37. package/dist/examples/profiling/per-call.d.ts +2 -0
  38. package/dist/examples/profiling/per-call.js +30 -0
  39. package/dist/examples/transcription/parakeet-ctc-filesystem.d.ts +2 -0
  40. package/dist/examples/transcription/parakeet-ctc-filesystem.js +40 -0
  41. package/dist/examples/transcription/parakeet-microphone-record.d.ts +2 -0
  42. package/dist/examples/transcription/parakeet-microphone-record.js +95 -0
  43. package/dist/examples/transcription/parakeet-sortformer.d.ts +2 -0
  44. package/dist/examples/transcription/parakeet-sortformer.js +115 -0
  45. package/dist/examples/transcription/parakeet-tdt-filesystem.d.ts +2 -0
  46. package/dist/examples/transcription/parakeet-tdt-filesystem.js +44 -0
  47. package/dist/examples/translation/translation-bergamot-pivot.d.ts +2 -0
  48. package/dist/examples/translation/translation-bergamot-pivot.js +73 -0
  49. package/dist/examples/translation/translation-llm-afriquegemma.d.ts +2 -0
  50. package/dist/examples/translation/translation-llm-afriquegemma.js +39 -0
  51. package/dist/index.d.ts +3 -1
  52. package/dist/index.js +2 -0
  53. package/dist/logging/index.d.ts +1 -1
  54. package/dist/logging/index.js +1 -1
  55. package/dist/logging/namespaces.d.ts +3 -9
  56. package/dist/logging/namespaces.js +2 -8
  57. package/dist/logging/registry.js +15 -1
  58. package/dist/models/registry/models.d.ts +1606 -245
  59. package/dist/models/registry/models.js +2127 -721
  60. package/dist/models/update-models/codegen.js +2 -2
  61. package/dist/models/update-models/history.d.ts +11 -0
  62. package/dist/models/update-models/history.js +24 -5
  63. package/dist/models/update-models/index.js +17 -16
  64. package/dist/models/update-models/naming.js +56 -0
  65. package/dist/profiling/aggregator.d.ts +15 -0
  66. package/dist/profiling/aggregator.js +100 -0
  67. package/dist/profiling/clock.d.ts +12 -0
  68. package/dist/profiling/clock.js +51 -0
  69. package/dist/profiling/controller.d.ts +33 -0
  70. package/dist/profiling/controller.js +123 -0
  71. package/dist/profiling/envelope.d.ts +10 -0
  72. package/dist/profiling/envelope.js +36 -0
  73. package/dist/profiling/events.d.ts +20 -0
  74. package/dist/profiling/events.js +37 -0
  75. package/dist/profiling/exporters.d.ts +10 -0
  76. package/dist/profiling/exporters.js +236 -0
  77. package/dist/profiling/index.d.ts +36 -0
  78. package/dist/profiling/index.js +31 -0
  79. package/dist/profiling/ring-buffer.d.ts +19 -0
  80. package/dist/profiling/ring-buffer.js +83 -0
  81. package/dist/profiling/types.d.ts +47 -0
  82. package/dist/profiling/types.js +1 -0
  83. package/dist/schemas/common.d.ts +1888 -133
  84. package/dist/schemas/common.js +2 -0
  85. package/dist/schemas/completion-stream.d.ts +31 -0
  86. package/dist/schemas/completion-stream.js +13 -0
  87. package/dist/schemas/download-asset.d.ts +14 -3
  88. package/dist/schemas/download-asset.js +3 -1
  89. package/dist/schemas/engine-addon-map.js +9 -6
  90. package/dist/schemas/get-model-info.d.ts +2 -0
  91. package/dist/schemas/get-model-info.js +1 -0
  92. package/dist/schemas/index.d.ts +2 -1
  93. package/dist/schemas/index.js +2 -1
  94. package/dist/schemas/llamacpp-config.d.ts +140 -14
  95. package/dist/schemas/llamacpp-config.js +11 -7
  96. package/dist/schemas/load-model.d.ts +9649 -2515
  97. package/dist/schemas/load-model.js +142 -182
  98. package/dist/schemas/model-src-utils.d.ts +10 -2
  99. package/dist/schemas/model-types.d.ts +19 -1
  100. package/dist/schemas/model-types.js +11 -0
  101. package/dist/schemas/ocr.d.ts +37 -0
  102. package/dist/schemas/ocr.js +5 -0
  103. package/dist/schemas/plugin.d.ts +51 -5
  104. package/dist/schemas/plugin.js +26 -0
  105. package/dist/schemas/profiling.d.ts +105 -0
  106. package/dist/schemas/profiling.js +66 -0
  107. package/dist/schemas/registry.d.ts +18 -0
  108. package/dist/schemas/registry.js +2 -0
  109. package/dist/schemas/reload-config.d.ts +126 -6
  110. package/dist/schemas/reload-config.js +1 -1
  111. package/dist/schemas/sdk-config.d.ts +2280 -24
  112. package/dist/schemas/sdk-config.js +6 -1
  113. package/dist/schemas/sdk-errors-client.d.ts +1 -0
  114. package/dist/schemas/sdk-errors-client.js +7 -0
  115. package/dist/schemas/sdk-errors-server.d.ts +3 -0
  116. package/dist/schemas/sdk-errors-server.js +15 -0
  117. package/dist/schemas/text-to-speech.d.ts +90 -68
  118. package/dist/schemas/text-to-speech.js +16 -33
  119. package/dist/schemas/transcription-config.d.ts +383 -0
  120. package/dist/schemas/{whispercpp-config.js → transcription-config.js} +29 -1
  121. package/dist/schemas/translation-config.d.ts +463 -8
  122. package/dist/schemas/translation-config.js +35 -2
  123. package/dist/server/bare/delegate-rpc-client.js +11 -1
  124. package/dist/server/bare/ops/load-model.d.ts +7 -1
  125. package/dist/server/bare/ops/load-model.js +41 -42
  126. package/dist/server/bare/ops/transcribe.d.ts +3 -0
  127. package/dist/server/bare/ops/transcribe.js +75 -0
  128. package/dist/server/bare/ops/translate.d.ts +2 -0
  129. package/dist/server/bare/ops/translate.js +12 -4
  130. package/dist/server/bare/plugins/index.d.ts +1 -0
  131. package/dist/server/bare/plugins/index.js +1 -0
  132. package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.d.ts +2 -1
  133. package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.js +8 -6
  134. package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +108 -3
  135. package/dist/server/bare/plugins/llamacpp-completion/plugin.js +19 -6
  136. package/dist/server/bare/plugins/llamacpp-embedding/plugin.d.ts +32 -2
  137. package/dist/server/bare/plugins/llamacpp-embedding/plugin.js +31 -17
  138. package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +325 -3
  139. package/dist/server/bare/plugins/nmtcpp-translation/plugin.js +117 -10
  140. package/dist/server/bare/plugins/onnx-ocr/plugin.d.ts +50 -2
  141. package/dist/server/bare/plugins/onnx-ocr/plugin.js +46 -5
  142. package/dist/server/bare/plugins/onnx-tts/plugin.d.ts +351 -4
  143. package/dist/server/bare/plugins/onnx-tts/plugin.js +81 -61
  144. package/dist/server/bare/plugins/parakeet-transcription/plugin.d.ts +317 -0
  145. package/dist/server/bare/plugins/parakeet-transcription/plugin.js +154 -0
  146. package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +209 -3
  147. package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +21 -9
  148. package/dist/server/bare/rag-hyperdb/rag-workspace-manager.js +2 -2
  149. package/dist/server/bare/registry/model-config-utils.js +3 -1
  150. package/dist/server/bare/utils/audio-input.d.ts +10 -0
  151. package/dist/server/bare/utils/audio-input.js +33 -0
  152. package/dist/server/error-handlers.d.ts +3 -2
  153. package/dist/server/error-handlers.js +11 -8
  154. package/dist/server/plugins/registry.js +5 -1
  155. package/dist/server/rpc/delegate-transport.d.ts +11 -3
  156. package/dist/server/rpc/delegate-transport.js +158 -3
  157. package/dist/server/rpc/handle-request.js +43 -4
  158. package/dist/server/rpc/handler-registry.js +7 -1
  159. package/dist/server/rpc/handler-utils.d.ts +5 -4
  160. package/dist/server/rpc/handler-utils.js +72 -31
  161. package/dist/server/rpc/handlers/completion-stream-delegated.d.ts +3 -1
  162. package/dist/server/rpc/handlers/completion-stream-delegated.js +11 -2
  163. package/dist/server/rpc/handlers/download-asset.js +55 -3
  164. package/dist/server/rpc/handlers/load-model/download-stats.d.ts +6 -0
  165. package/dist/server/rpc/handlers/load-model/download-stats.js +87 -0
  166. package/dist/server/rpc/handlers/load-model/handler.js +108 -123
  167. package/dist/server/rpc/handlers/load-model/http.d.ts +2 -1
  168. package/dist/server/rpc/handlers/load-model/http.js +21 -5
  169. package/dist/server/rpc/handlers/load-model/hyperdrive.d.ts +2 -1
  170. package/dist/server/rpc/handlers/load-model/hyperdrive.js +19 -14
  171. package/dist/server/rpc/handlers/load-model/registry.d.ts +2 -1
  172. package/dist/server/rpc/handlers/load-model/registry.js +123 -130
  173. package/dist/server/rpc/handlers/load-model/resolve.d.ts +2 -0
  174. package/dist/server/rpc/handlers/load-model/resolve.js +55 -22
  175. package/dist/server/rpc/handlers/load-model/types.d.ts +29 -0
  176. package/dist/server/rpc/handlers/load-model/types.js +1 -0
  177. package/dist/server/rpc/handlers/load-model-delegated.d.ts +5 -1
  178. package/dist/server/rpc/handlers/load-model-delegated.js +35 -7
  179. package/dist/server/rpc/handlers/plugin-dispatch.js +15 -10
  180. package/dist/server/rpc/handlers/plugin-invoke.js +56 -51
  181. package/dist/server/rpc/handlers/rag.js +24 -0
  182. package/dist/server/rpc/handlers/unload-model-delegated.d.ts +3 -0
  183. package/dist/server/rpc/handlers/unload-model-delegated.js +32 -0
  184. package/dist/server/rpc/profiling/context.d.ts +18 -0
  185. package/dist/server/rpc/profiling/context.js +38 -0
  186. package/dist/server/rpc/profiling/delegation-profiler.d.ts +32 -0
  187. package/dist/server/rpc/profiling/delegation-profiler.js +154 -0
  188. package/dist/server/rpc/profiling/index.d.ts +5 -0
  189. package/dist/server/rpc/profiling/index.js +4 -0
  190. package/dist/server/rpc/profiling/operation-metrics.d.ts +25 -0
  191. package/dist/server/rpc/profiling/operation-metrics.js +199 -0
  192. package/dist/server/rpc/profiling/operation-wrappers.d.ts +18 -0
  193. package/dist/server/rpc/profiling/operation-wrappers.js +124 -0
  194. package/dist/server/rpc/profiling/profiler.d.ts +13 -0
  195. package/dist/server/rpc/profiling/profiler.js +97 -0
  196. package/dist/server/utils/cache.d.ts +2 -1
  197. package/dist/server/utils/cache.js +5 -1
  198. package/dist/server/utils/checksum.d.ts +2 -0
  199. package/dist/server/utils/checksum.js +7 -0
  200. package/dist/server/utils/formatting.d.ts +6 -0
  201. package/dist/server/utils/formatting.js +35 -0
  202. package/dist/server/worker.js +2 -1
  203. package/dist/utils/errors-client.d.ts +3 -0
  204. package/dist/utils/errors-client.js +6 -0
  205. package/dist/utils/errors-server.d.ts +9 -0
  206. package/dist/utils/errors-server.js +15 -0
  207. package/dist/utils/global-singleton.d.ts +2 -0
  208. package/dist/utils/global-singleton.js +10 -0
  209. package/package.json +14 -17
  210. package/dist/schemas/whispercpp-config.d.ts +0 -70
  211. package/dist/server/bare/plugins/whispercpp-transcription/ops/transcribe-stream.d.ts +0 -3
  212. package/dist/server/bare/plugins/whispercpp-transcription/ops/transcribe-stream.js +0 -81
  213. /package/dist/examples/{whispercpp-filesystem.d.ts → transcription/whispercpp-filesystem.d.ts} +0 -0
  214. /package/dist/examples/{whispercpp-filesystem.js → transcription/whispercpp-filesystem.js} +0 -0
  215. /package/dist/examples/{whispercpp-microphone-record.d.ts → transcription/whispercpp-microphone-record.d.ts} +0 -0
  216. /package/dist/examples/{whispercpp-microphone-record.js → transcription/whispercpp-microphone-record.js} +0 -0
  217. /package/dist/examples/{whispercpp-prompt.d.ts → transcription/whispercpp-prompt.d.ts} +0 -0
  218. /package/dist/examples/{whispercpp-prompt.js → transcription/whispercpp-prompt.js} +0 -0
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Declarative extraction of operation-level metrics from request/response data.
3
+ * Used by operation wrappers to capture handler-specific profiling events.
4
+ */
5
+ const metricsRegistry = new Map();
6
+ function extractDownloadStatsGauges(stats, gauges) {
7
+ if (stats?.downloadTimeMs !== undefined) {
8
+ gauges["downloadTime"] = stats.downloadTimeMs;
9
+ }
10
+ if (stats?.totalBytesDownloaded !== undefined) {
11
+ gauges["totalBytesDownloaded"] = stats.totalBytesDownloaded;
12
+ }
13
+ if (stats?.downloadSpeedBps !== undefined) {
14
+ gauges["downloadSpeedBps"] = stats.downloadSpeedBps;
15
+ }
16
+ }
17
+ export function registerOperationMetrics(config) {
18
+ metricsRegistry.set(config.op, config);
19
+ }
20
+ export function buildOperationEvent(op, profileId, ts, executionMs, request, finalResponse, ttfb) {
21
+ const config = metricsRegistry.get(op);
22
+ if (!config) {
23
+ return {
24
+ ts,
25
+ op,
26
+ kind: "handler",
27
+ profileId,
28
+ ms: executionMs,
29
+ };
30
+ }
31
+ const gauges = {};
32
+ if (ttfb !== undefined) {
33
+ gauges["ttfb"] = ttfb;
34
+ }
35
+ if (config.fromRequest && request) {
36
+ const extracted = config.fromRequest(request);
37
+ if (extracted)
38
+ Object.assign(gauges, extracted);
39
+ }
40
+ if (config.fromFinalChunk && finalResponse) {
41
+ const extracted = config.fromFinalChunk(finalResponse);
42
+ if (extracted)
43
+ Object.assign(gauges, extracted);
44
+ }
45
+ if (config.fromResult && finalResponse) {
46
+ const extracted = config.fromResult(finalResponse);
47
+ if (extracted)
48
+ Object.assign(gauges, extracted);
49
+ }
50
+ const requestTags = config.getTags?.(request);
51
+ const resultTags = config.getTagsFromResult?.(finalResponse);
52
+ const tags = { ...requestTags, ...resultTags };
53
+ const hasGauges = Object.keys(gauges).length > 0;
54
+ const hasTags = Object.keys(tags).length > 0;
55
+ const event = {
56
+ ts,
57
+ op: config.op,
58
+ kind: config.kind,
59
+ profileId,
60
+ ms: executionMs,
61
+ };
62
+ if (hasGauges) {
63
+ event.gauges = gauges;
64
+ }
65
+ if (hasTags) {
66
+ event.tags = tags;
67
+ }
68
+ return event;
69
+ }
70
+ registerOperationMetrics({
71
+ op: "completionStream",
72
+ kind: "handler",
73
+ getTags: (req) => (req.modelId ? { modelId: req.modelId } : {}),
74
+ fromFinalChunk: (res) => {
75
+ if (!res.stats)
76
+ return undefined;
77
+ const gauges = {};
78
+ if (res.stats.timeToFirstToken !== undefined)
79
+ gauges["timeToFirstToken"] = res.stats.timeToFirstToken;
80
+ if (res.stats.tokensPerSecond !== undefined)
81
+ gauges["tokensPerSecond"] = res.stats.tokensPerSecond;
82
+ if (res.stats.cacheTokens !== undefined)
83
+ gauges["cacheTokens"] = res.stats.cacheTokens;
84
+ return Object.keys(gauges).length > 0 ? gauges : undefined;
85
+ },
86
+ });
87
+ registerOperationMetrics({
88
+ op: "translate",
89
+ kind: "handler",
90
+ getTags: (req) => (req.modelId ? { modelId: req.modelId } : {}),
91
+ fromFinalChunk: (res) => {
92
+ if (!res.stats)
93
+ return undefined;
94
+ const gauges = {};
95
+ if (res.stats.processedTokens !== undefined)
96
+ gauges["processedTokens"] = res.stats.processedTokens;
97
+ if (res.stats.processingTime !== undefined)
98
+ gauges["processingTime"] = res.stats.processingTime;
99
+ return Object.keys(gauges).length > 0 ? gauges : undefined;
100
+ },
101
+ });
102
+ registerOperationMetrics({
103
+ op: "transcribeStream",
104
+ kind: "handler",
105
+ getTags: (req) => (req.modelId ? { modelId: req.modelId } : {}),
106
+ });
107
+ registerOperationMetrics({
108
+ op: "textToSpeech",
109
+ kind: "handler",
110
+ getTags: (req) => (req.modelId ? { modelId: req.modelId } : {}),
111
+ });
112
+ registerOperationMetrics({
113
+ op: "embed",
114
+ kind: "handler",
115
+ getTags: (req) => (req.modelId ? { modelId: req.modelId } : {}),
116
+ });
117
+ registerOperationMetrics({
118
+ op: "ocrStream",
119
+ kind: "handler",
120
+ getTags: (req) => (req.modelId ? { modelId: req.modelId } : {}),
121
+ fromFinalChunk: (res) => {
122
+ if (!res.stats)
123
+ return undefined;
124
+ const gauges = {};
125
+ if (res.stats.detectionTime !== undefined)
126
+ gauges["detectionTime"] = res.stats.detectionTime;
127
+ if (res.stats.recognitionTime !== undefined)
128
+ gauges["recognitionTime"] = res.stats.recognitionTime;
129
+ if (res.stats.totalTime !== undefined)
130
+ gauges["totalTime"] = res.stats.totalTime;
131
+ return Object.keys(gauges).length > 0 ? gauges : undefined;
132
+ },
133
+ });
134
+ registerOperationMetrics({
135
+ op: "pluginInvoke",
136
+ kind: "handler",
137
+ getTags: (req) => {
138
+ const tags = {};
139
+ if (req.modelId)
140
+ tags["modelId"] = req.modelId;
141
+ if (req.handler)
142
+ tags["handler"] = req.handler;
143
+ return tags;
144
+ },
145
+ });
146
+ registerOperationMetrics({
147
+ op: "pluginInvokeStream",
148
+ kind: "handler",
149
+ getTags: (req) => {
150
+ const tags = {};
151
+ if (req.modelId)
152
+ tags["modelId"] = req.modelId;
153
+ if (req.handler)
154
+ tags["handler"] = req.handler;
155
+ return tags;
156
+ },
157
+ });
158
+ registerOperationMetrics({
159
+ op: "loadModel",
160
+ kind: "handler",
161
+ getTags: (req) => (req.modelType ? { modelType: req.modelType } : {}),
162
+ getTagsFromResult: (res) => {
163
+ const sourceType = res.__profilingMeta?.sourceType;
164
+ return sourceType ? { sourceType } : undefined;
165
+ },
166
+ fromResult: (res) => {
167
+ const meta = res.__profilingMeta;
168
+ if (!meta)
169
+ return undefined;
170
+ const gauges = {};
171
+ extractDownloadStatsGauges(meta.downloadStats, gauges);
172
+ if (meta.modelInitializationTimeMs !== undefined) {
173
+ gauges["modelInitializationTime"] = meta.modelInitializationTimeMs;
174
+ }
175
+ if (meta.totalLoadTimeMs !== undefined) {
176
+ gauges["totalLoadTime"] = meta.totalLoadTimeMs;
177
+ }
178
+ return Object.keys(gauges).length > 0 ? gauges : undefined;
179
+ },
180
+ });
181
+ registerOperationMetrics({
182
+ op: "downloadAsset",
183
+ kind: "handler",
184
+ getTagsFromResult: (res) => {
185
+ const sourceType = res.__profilingMeta?.sourceType;
186
+ return sourceType ? { sourceType } : undefined;
187
+ },
188
+ fromResult: (res) => {
189
+ const meta = res.__profilingMeta;
190
+ if (!meta)
191
+ return undefined;
192
+ const gauges = {};
193
+ extractDownloadStatsGauges(meta.downloadStats, gauges);
194
+ if (meta.totalDownloadTimeMs !== undefined) {
195
+ gauges["totalDownloadTime"] = meta.totalDownloadTimeMs;
196
+ }
197
+ return Object.keys(gauges).length > 0 ? gauges : undefined;
198
+ },
199
+ });
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Generic wrappers for profiling handler execution.
3
+ * Used to wrap dispatch/invoke functions with timing capture.
4
+ */
5
+ import { type PerCallProfiling } from "../../../schemas/index";
6
+ export interface ProfiledReplyOptions<TRequest> {
7
+ op: string;
8
+ request: TRequest;
9
+ perCall?: PerCallProfiling;
10
+ }
11
+ export interface ProfiledStreamOptions<TRequest> {
12
+ op: string;
13
+ request: TRequest;
14
+ perCall?: PerCallProfiling;
15
+ }
16
+ export declare function profileReplyHandler<TRequest, TResponse>(options: ProfiledReplyOptions<TRequest>, handler: () => Promise<TResponse>): Promise<TResponse>;
17
+ export declare function profileStreamHandler<TRequest, TResponse>(options: ProfiledStreamOptions<TRequest>, handler: () => AsyncGenerator<TResponse>): AsyncGenerator<TResponse>;
18
+ //# sourceMappingURL=operation-wrappers.d.ts.map
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Generic wrappers for profiling handler execution.
3
+ * Used to wrap dispatch/invoke functions with timing capture.
4
+ */
5
+ import { PROFILING_KEY, } from "../../../schemas/index.js";
6
+ import { nowMs, generateProfileId } from "../../../profiling/clock.js";
7
+ import { record, shouldProfile } from "../../../profiling/controller.js";
8
+ import { buildOperationEvent } from "./operation-metrics.js";
9
+ function getRequestProfilingMeta(request) {
10
+ if (!request || typeof request !== "object") {
11
+ return undefined;
12
+ }
13
+ const meta = request[PROFILING_KEY];
14
+ if (!meta || typeof meta !== "object") {
15
+ return undefined;
16
+ }
17
+ return meta;
18
+ }
19
+ function resolvePerCallProfiling(options) {
20
+ if (options.perCall) {
21
+ return options.perCall;
22
+ }
23
+ const meta = getRequestProfilingMeta(options.request);
24
+ if (!meta) {
25
+ return undefined;
26
+ }
27
+ if (meta.enabled === false) {
28
+ return { enabled: false };
29
+ }
30
+ return {
31
+ enabled: true,
32
+ includeServerBreakdown: meta.includeServer,
33
+ mode: meta.mode,
34
+ };
35
+ }
36
+ function recordOperationEvent(params) {
37
+ const event = buildOperationEvent(params.options.op, params.profileId, params.startTs, params.executionMs, params.options.request, params.finalResponse, params.ttfb);
38
+ if (!event)
39
+ return;
40
+ if (params.errored) {
41
+ event.tags = { ...event.tags, error: "true" };
42
+ }
43
+ if (params.count !== undefined && params.count > 0) {
44
+ event.count = params.count;
45
+ }
46
+ record(event);
47
+ }
48
+ export async function profileReplyHandler(options, handler) {
49
+ const perCall = resolvePerCallProfiling(options);
50
+ if (!shouldProfile(options.op, perCall)) {
51
+ return handler();
52
+ }
53
+ const profileId = generateProfileId();
54
+ const startTs = nowMs();
55
+ try {
56
+ const result = await handler();
57
+ const executionMs = nowMs() - startTs;
58
+ recordOperationEvent({
59
+ options,
60
+ profileId,
61
+ startTs,
62
+ executionMs,
63
+ finalResponse: result,
64
+ });
65
+ return result;
66
+ }
67
+ catch (error) {
68
+ const executionMs = nowMs() - startTs;
69
+ recordOperationEvent({
70
+ options,
71
+ profileId,
72
+ startTs,
73
+ executionMs,
74
+ errored: true,
75
+ });
76
+ throw error;
77
+ }
78
+ }
79
+ export async function* profileStreamHandler(options, handler) {
80
+ const perCall = resolvePerCallProfiling(options);
81
+ if (!shouldProfile(options.op, perCall)) {
82
+ yield* handler();
83
+ return;
84
+ }
85
+ const profileId = generateProfileId();
86
+ const startTs = nowMs();
87
+ let ttfb;
88
+ let lastChunk;
89
+ let chunkCount = 0;
90
+ try {
91
+ for await (const chunk of handler()) {
92
+ if (ttfb === undefined) {
93
+ ttfb = nowMs() - startTs;
94
+ }
95
+ chunkCount++;
96
+ lastChunk = chunk;
97
+ yield chunk;
98
+ }
99
+ const executionMs = nowMs() - startTs;
100
+ recordOperationEvent({
101
+ options,
102
+ profileId,
103
+ startTs,
104
+ executionMs,
105
+ finalResponse: lastChunk,
106
+ ttfb,
107
+ count: chunkCount,
108
+ });
109
+ }
110
+ catch (error) {
111
+ const executionMs = nowMs() - startTs;
112
+ recordOperationEvent({
113
+ options,
114
+ profileId,
115
+ startTs,
116
+ executionMs,
117
+ finalResponse: lastChunk,
118
+ ttfb,
119
+ count: chunkCount,
120
+ errored: true,
121
+ });
122
+ throw error;
123
+ }
124
+ }
@@ -0,0 +1,13 @@
1
+ import { type Response, type ProfilingRequestMeta } from "../../../schemas/index";
2
+ import { type ServerProfilingContext } from "./context";
3
+ export type ServerProfiler = {
4
+ markRequestParsed: (ms: number) => void;
5
+ markRequestValidated: (ms: number) => void;
6
+ startHandler: () => void;
7
+ endHandler: () => void;
8
+ serialize: (response?: Response, final?: boolean) => string;
9
+ serializeError: (json: string) => string;
10
+ getContext: () => ServerProfilingContext | undefined;
11
+ };
12
+ export declare function createServerProfiler(meta?: ProfilingRequestMeta): ServerProfiler;
13
+ //# sourceMappingURL=profiler.d.ts.map
@@ -0,0 +1,97 @@
1
+ import { nowMs } from "../../../profiling/index.js";
2
+ import { responseSchema, DELEGATION_BREAKDOWN_KEY, OPERATION_EVENT_KEY, PROFILING_TRAILER_KEY, } from "../../../schemas/index.js";
3
+ import { createProfilingContext, injectProfilingIntoString, } from "./context.js";
4
+ const noopProfiler = {
5
+ markRequestParsed: () => { },
6
+ markRequestValidated: () => { },
7
+ startHandler: () => { },
8
+ endHandler: () => { },
9
+ serialize: (response) => {
10
+ if (!response)
11
+ return "";
12
+ const extended = response;
13
+ const delegation = extended[DELEGATION_BREAKDOWN_KEY];
14
+ const operation = extended[OPERATION_EVENT_KEY];
15
+ const json = JSON.stringify(responseSchema.parse(response));
16
+ if (delegation || operation) {
17
+ const opts = {};
18
+ if (delegation)
19
+ opts.delegation = delegation;
20
+ if (operation)
21
+ opts.operation = operation;
22
+ return injectProfilingIntoString(json, opts);
23
+ }
24
+ return json;
25
+ },
26
+ serializeError: (json) => json,
27
+ getContext: () => undefined,
28
+ };
29
+ function createActiveProfiler(meta) {
30
+ const ctx = createProfilingContext(meta);
31
+ let handlerStart = 0;
32
+ let handlerEnded = false;
33
+ let cachedDelegation;
34
+ let cachedOperation;
35
+ return {
36
+ markRequestParsed: (ms) => {
37
+ ctx.jsonParseMs = ms;
38
+ },
39
+ markRequestValidated: (ms) => {
40
+ ctx.zodValidationMs = ms;
41
+ },
42
+ startHandler: () => {
43
+ handlerStart = nowMs();
44
+ handlerEnded = false;
45
+ },
46
+ endHandler: () => {
47
+ if (handlerEnded)
48
+ return;
49
+ handlerEnded = true;
50
+ ctx.handlerExecutionMs = nowMs() - handlerStart;
51
+ },
52
+ serialize: (response, final = true) => {
53
+ if (!response) {
54
+ const opts = { ctx };
55
+ if (cachedDelegation)
56
+ opts.delegation = cachedDelegation;
57
+ if (cachedOperation)
58
+ opts.operation = cachedOperation;
59
+ return injectProfilingIntoString(`{"${PROFILING_TRAILER_KEY}":true}`, opts);
60
+ }
61
+ const extended = response;
62
+ const delegation = extended[DELEGATION_BREAKDOWN_KEY];
63
+ const operation = extended[OPERATION_EVENT_KEY];
64
+ if (delegation)
65
+ cachedDelegation = delegation;
66
+ if (operation)
67
+ cachedOperation = operation;
68
+ const zodStart = nowMs();
69
+ const validated = responseSchema.parse(response);
70
+ ctx.responseZodValidationMs =
71
+ (ctx.responseZodValidationMs ?? 0) + (nowMs() - zodStart);
72
+ const stringifyStart = nowMs();
73
+ const json = JSON.stringify(validated);
74
+ ctx.responseStringifyMs =
75
+ (ctx.responseStringifyMs ?? 0) + (nowMs() - stringifyStart);
76
+ if (final) {
77
+ const opts = { ctx };
78
+ if (delegation)
79
+ opts.delegation = delegation;
80
+ if (operation)
81
+ opts.operation = operation;
82
+ return injectProfilingIntoString(json, opts);
83
+ }
84
+ return json;
85
+ },
86
+ serializeError: (json) => injectProfilingIntoString(json, { ctx }),
87
+ getContext: () => ctx,
88
+ };
89
+ }
90
+ export function createServerProfiler(meta) {
91
+ if (meta?.includeServer &&
92
+ typeof meta.id === "string" &&
93
+ meta.id.length > 0) {
94
+ return createActiveProfiler(meta);
95
+ }
96
+ return noopProfiler;
97
+ }
@@ -20,6 +20,7 @@ export declare function getShardPath(hyperdriveKey: string, shardFilename: strin
20
20
  /**
21
21
  * Check if all shards exist and are valid (size + checksum check)
22
22
  * Returns array of missing/invalid shard indices (0-based)
23
+ * @param onChecksumTimeMs - Optional callback to report checksum validation time
23
24
  */
24
- export declare function checkShardCompleteness(hyperdriveKey: string, shardFilenames: readonly string[], shardMetadata: readonly ShardFileMetadata[]): Promise<number[]>;
25
+ export declare function checkShardCompleteness(hyperdriveKey: string, shardFilenames: readonly string[], shardMetadata: readonly ShardFileMetadata[], onChecksumTimeMs?: (ms: number) => void): Promise<number[]>;
25
26
  //# sourceMappingURL=cache.d.ts.map
@@ -5,6 +5,7 @@ import { getConfiguredCacheDir } from "../bare/registry/config-registry.js";
5
5
  import { calculateFileChecksum } from "./checksum.js";
6
6
  import { validateAndJoinPath } from "./path-security.js";
7
7
  import { getServerLogger } from "../../logging/index.js";
8
+ import { nowMs } from "../../profiling/index.js";
8
9
  const logger = getServerLogger();
9
10
  export function getCacheDir(subDir) {
10
11
  const homeDir = getEnv().HOME_DIR;
@@ -79,8 +80,9 @@ export function getShardPath(hyperdriveKey, shardFilename) {
79
80
  /**
80
81
  * Check if all shards exist and are valid (size + checksum check)
81
82
  * Returns array of missing/invalid shard indices (0-based)
83
+ * @param onChecksumTimeMs - Optional callback to report checksum validation time
82
84
  */
83
- export async function checkShardCompleteness(hyperdriveKey, shardFilenames, shardMetadata) {
85
+ export async function checkShardCompleteness(hyperdriveKey, shardFilenames, shardMetadata, onChecksumTimeMs) {
84
86
  const invalidIndices = [];
85
87
  for (let i = 0; i < shardFilenames.length; i++) {
86
88
  const shardPath = getShardPath(hyperdriveKey, shardFilenames[i]);
@@ -97,7 +99,9 @@ export async function checkShardCompleteness(hyperdriveKey, shardFilenames, shar
97
99
  continue;
98
100
  }
99
101
  if (fileMeta.sha256Checksum) {
102
+ const start = nowMs();
100
103
  const actualChecksum = await calculateFileChecksum(shardPath);
104
+ onChecksumTimeMs?.(nowMs() - start);
101
105
  if (actualChecksum !== fileMeta.sha256Checksum) {
102
106
  logger.warn(`File ${i + 1} checksum mismatch for ${fileMeta.filename}. Expected: ${fileMeta.sha256Checksum}. Actual: ${actualChecksum}. Will re-download.`);
103
107
  invalidIndices.push(i);
@@ -1,2 +1,4 @@
1
+ import type { DownloadMetricsHooks } from "../rpc/handlers/load-model/types";
1
2
  export declare function calculateFileChecksum(filePath: string): Promise<string>;
3
+ export declare function measureChecksum(filePath: string, hooks?: DownloadMetricsHooks): Promise<string>;
2
4
  //# sourceMappingURL=checksum.d.ts.map
@@ -1,5 +1,6 @@
1
1
  import fs from "bare-fs";
2
2
  import crypto from "bare-crypto";
3
+ import { nowMs } from "../../profiling/index.js";
3
4
  export async function calculateFileChecksum(filePath) {
4
5
  return new Promise((resolve, reject) => {
5
6
  try {
@@ -22,3 +23,9 @@ export async function calculateFileChecksum(filePath) {
22
23
  }
23
24
  });
24
25
  }
26
+ export async function measureChecksum(filePath, hooks) {
27
+ const start = nowMs();
28
+ const checksum = await calculateFileChecksum(filePath);
29
+ hooks?.addChecksumValidationTimeMs(nowMs() - start);
30
+ return checksum;
31
+ }
@@ -2,6 +2,12 @@
2
2
  * Generate a short hash (16 characters) from any input string
3
3
  */
4
4
  export declare function generateShortHash(input: string): string;
5
+ /**
6
+ * Create a stable, deterministic string representation of a config object.
7
+ * - Recursively sorts all object keys
8
+ * - Normalizes ModelDescriptor objects to their src string
9
+ */
10
+ export declare function canonicalConfigString(config: Record<string, unknown> | undefined): string;
5
11
  /**
6
12
  * Calculate progress percentage with bounds checking and consistent formatting
7
13
  * @param current - Current progress value
@@ -9,6 +9,41 @@ export function generateShortHash(input) {
9
9
  .digest("hex");
10
10
  return hash.substring(0, 16);
11
11
  }
12
+ function isModelDescriptor(value) {
13
+ return (typeof value === "object" &&
14
+ value !== null &&
15
+ "src" in value &&
16
+ typeof value.src === "string");
17
+ }
18
+ function normalizeValue(value) {
19
+ if (isModelDescriptor(value)) {
20
+ return value.src;
21
+ }
22
+ if (Array.isArray(value)) {
23
+ return value.map(normalizeValue);
24
+ }
25
+ if (typeof value === "object" && value !== null) {
26
+ return normalizeConfig(value);
27
+ }
28
+ return value;
29
+ }
30
+ function normalizeConfig(config) {
31
+ const result = {};
32
+ for (const key of Object.keys(config).sort()) {
33
+ result[key] = normalizeValue(config[key]);
34
+ }
35
+ return result;
36
+ }
37
+ /**
38
+ * Create a stable, deterministic string representation of a config object.
39
+ * - Recursively sorts all object keys
40
+ * - Normalizes ModelDescriptor objects to their src string
41
+ */
42
+ export function canonicalConfigString(config) {
43
+ if (!config)
44
+ return "{}";
45
+ return JSON.stringify(normalizeConfig(config));
46
+ }
12
47
  /**
13
48
  * Calculate progress percentage with bounds checking and consistent formatting
14
49
  * @param current - Current progress value
@@ -4,7 +4,7 @@
4
4
  import { initializeWorkerCore, ensureRPCSetup } from "./worker-core.js";
5
5
  import { registerPlugin } from "./plugins/index.js";
6
6
  import { getServerLogger } from "../logging/index.js";
7
- import { llmPlugin, embeddingsPlugin, whisperPlugin, nmtPlugin, ttsPlugin, ocrPlugin, } from "./bare/plugins/index.js";
7
+ import { llmPlugin, embeddingsPlugin, whisperPlugin, parakeetPlugin, nmtPlugin, ttsPlugin, ocrPlugin, } from "./bare/plugins/index.js";
8
8
  const { hasRPCConfig } = initializeWorkerCore();
9
9
  const logger = getServerLogger();
10
10
  logger.info("🐻 Hello from Bare");
@@ -12,6 +12,7 @@ logger.info("🐻 Hello from Bare");
12
12
  registerPlugin(llmPlugin);
13
13
  registerPlugin(embeddingsPlugin);
14
14
  registerPlugin(whisperPlugin);
15
+ registerPlugin(parakeetPlugin);
15
16
  registerPlugin(nmtPlugin);
16
17
  registerPlugin(ttsPlugin);
17
18
  registerPlugin(ocrPlugin);
@@ -131,4 +131,7 @@ export declare class SetConfigFailedError extends QvacErrorBase {
131
131
  export declare class ModelRegistryQueryFailedError extends QvacErrorBase {
132
132
  constructor(details?: string, cause?: unknown);
133
133
  }
134
+ export declare class ProfilerInvalidCapacityError extends QvacErrorBase {
135
+ constructor(minCapacity: number, cause?: unknown);
136
+ }
134
137
  //# sourceMappingURL=errors-client.d.ts.map
@@ -232,3 +232,9 @@ export class ModelRegistryQueryFailedError extends QvacErrorBase {
232
232
  super(createErrorOptions(SDK_SERVER_ERROR_CODES.QVAC_MODEL_REGISTRY_QUERY_FAILED, details ? [details] : undefined, cause));
233
233
  }
234
234
  }
235
+ // ============== Profiler Errors ==============
236
+ export class ProfilerInvalidCapacityError extends QvacErrorBase {
237
+ constructor(minCapacity, cause) {
238
+ super(createErrorOptions(SDK_CLIENT_ERROR_CODES.PROFILER_INVALID_CAPACITY, [minCapacity], cause));
239
+ }
240
+ }
@@ -35,6 +35,9 @@ export declare class TtsArtifactsRequiredError extends QvacErrorBase {
35
35
  export declare class TtsReferenceAudioRequiredError extends QvacErrorBase {
36
36
  constructor(cause?: unknown);
37
37
  }
38
+ export declare class ParakeetArtifactsRequiredError extends QvacErrorBase {
39
+ constructor(details?: string, cause?: unknown);
40
+ }
38
41
  export declare class ModelUnloadFailedError extends QvacErrorBase {
39
42
  constructor(modelId?: string, cause?: unknown);
40
43
  }
@@ -209,6 +212,12 @@ export declare class PluginResponseValidationFailedError extends QvacErrorBase {
209
212
  export declare class PluginAlreadyRegisteredError extends QvacErrorBase {
210
213
  constructor(modelType: string, cause?: unknown);
211
214
  }
215
+ export declare class PluginModelTypeReservedError extends QvacErrorBase {
216
+ constructor(modelType: string, cause?: unknown);
217
+ }
218
+ export declare class PluginLoadConfigValidationFailedError extends QvacErrorBase {
219
+ constructor(modelType: string, details: string, cause?: unknown);
220
+ }
212
221
  export declare class PluginHandlerTypeMismatchError extends QvacErrorBase {
213
222
  constructor(handlerName: string, expected: string, actual: string, cause?: unknown);
214
223
  }
@@ -63,6 +63,11 @@ export class TtsReferenceAudioRequiredError extends QvacErrorBase {
63
63
  super(createErrorOptions(SDK_SERVER_ERROR_CODES.TTS_REFERENCE_AUDIO_REQUIRED, undefined, cause));
64
64
  }
65
65
  }
66
+ export class ParakeetArtifactsRequiredError extends QvacErrorBase {
67
+ constructor(details, cause) {
68
+ super(createErrorOptions(SDK_SERVER_ERROR_CODES.PARAKEET_ARTIFACTS_REQUIRED, details ? [details] : undefined, cause));
69
+ }
70
+ }
66
71
  // ============== Model Unloading Errors ==============
67
72
  export class ModelUnloadFailedError extends QvacErrorBase {
68
73
  constructor(modelId, cause) {
@@ -366,6 +371,16 @@ export class PluginAlreadyRegisteredError extends QvacErrorBase {
366
371
  super(createErrorOptions(SDK_SERVER_ERROR_CODES.PLUGIN_ALREADY_REGISTERED, [modelType], cause));
367
372
  }
368
373
  }
374
+ export class PluginModelTypeReservedError extends QvacErrorBase {
375
+ constructor(modelType, cause) {
376
+ super(createErrorOptions(SDK_SERVER_ERROR_CODES.PLUGIN_MODEL_TYPE_RESERVED, [modelType], cause));
377
+ }
378
+ }
379
+ export class PluginLoadConfigValidationFailedError extends QvacErrorBase {
380
+ constructor(modelType, details, cause) {
381
+ super(createErrorOptions(SDK_SERVER_ERROR_CODES.PLUGIN_LOAD_CONFIG_VALIDATION_FAILED, [modelType, details], cause));
382
+ }
383
+ }
369
384
  export class PluginHandlerTypeMismatchError extends QvacErrorBase {
370
385
  constructor(handlerName, expected, actual, cause) {
371
386
  super(createErrorOptions(SDK_SERVER_ERROR_CODES.PLUGIN_HANDLER_TYPE_MISMATCH, [handlerName, expected, actual], cause));
@@ -0,0 +1,2 @@
1
+ export declare function getGlobalSingleton<T>(key: symbol, create: () => T): T;
2
+ //# sourceMappingURL=global-singleton.d.ts.map
@@ -0,0 +1,10 @@
1
+ export function getGlobalSingleton(key, create) {
2
+ const global = globalThis;
3
+ const existing = global[key];
4
+ if (existing !== undefined) {
5
+ return existing;
6
+ }
7
+ const value = create();
8
+ global[key] = value;
9
+ return value;
10
+ }