@qvac/sdk 0.8.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +24 -1
- package/README.md +191 -373
- package/dist/client/api/cancel.d.ts +4 -22
- package/dist/client/api/cancel.js +6 -25
- package/dist/client/api/completion-stream.d.ts +30 -24
- package/dist/client/api/completion-stream.js +70 -121
- package/dist/client/api/delete-cache.js +2 -3
- package/dist/client/api/download-asset.d.ts +5 -6
- package/dist/client/api/download-asset.js +20 -16
- package/dist/client/api/embed.d.ts +4 -21
- package/dist/client/api/embed.js +14 -4
- package/dist/client/api/index.d.ts +2 -6
- package/dist/client/api/index.js +2 -6
- package/dist/client/api/load-model.d.ts +21 -49
- package/dist/client/api/load-model.js +134 -40
- package/dist/client/api/logging-stream.d.ts +4 -7
- package/dist/client/api/logging-stream.js +5 -9
- package/dist/client/api/ping.d.ts +11 -0
- package/dist/client/api/ping.js +18 -0
- package/dist/client/api/provide.d.ts +1 -1
- package/dist/client/api/provide.js +3 -4
- package/dist/client/api/rag.d.ts +21 -216
- package/dist/client/api/rag.js +36 -396
- package/dist/client/api/stop-provider.d.ts +1 -1
- package/dist/client/api/stop-provider.js +3 -4
- 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 -9
- package/dist/client/api/transcribe.js +9 -11
- package/dist/client/api/translate.d.ts +3 -3
- package/dist/client/api/translate.js +15 -15
- package/dist/client/api/unload-model.d.ts +1 -5
- package/dist/client/api/unload-model.js +4 -17
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/logging-stream-registry.d.ts +1 -1
- package/dist/client/logging-stream-registry.js +13 -14
- package/dist/client/rpc/bare-client.d.ts +139 -3
- package/dist/client/rpc/bare-client.js +16 -117
- package/dist/client/rpc/bare-rpc-client.d.ts +4 -0
- package/dist/client/rpc/bare-rpc-client.js +87 -0
- package/dist/client/rpc/expo-rpc-client.d.ts +1 -2
- package/dist/client/rpc/expo-rpc-client.js +14 -57
- package/dist/client/rpc/node-rpc-client.d.ts +8 -3
- package/dist/client/rpc/node-rpc-client.js +62 -218
- package/dist/client/rpc/rpc-client.d.ts +2 -3
- package/dist/client/rpc/rpc-client.js +49 -184
- package/dist/constants/audio.d.ts +2 -1
- package/dist/constants/audio.js +17 -1
- package/dist/constants/index.d.ts +0 -1
- package/dist/constants/index.js +0 -1
- package/dist/examples/delegated-inference/consumer.js +2 -3
- package/dist/examples/download-with-cancel.js +4 -3
- package/dist/examples/embed-hyperdrive.d.ts +2 -0
- package/dist/examples/embed-hyperdrive.js +19 -0
- package/dist/examples/kv-cache-cleanup.js +2 -1
- package/dist/examples/kv-cache-custom-key.js +2 -16
- package/dist/examples/kv-cache-example.js +2 -1
- package/dist/examples/llamacpp-file-logging.d.ts +2 -0
- package/dist/examples/{logging-file-transport.js → llamacpp-file-logging.js} +8 -3
- package/dist/examples/llamacpp-filesystem.js +2 -2
- package/dist/examples/llamacpp-http.js +1 -0
- package/dist/examples/llamacpp-hyperdrive.d.ts +2 -0
- package/dist/examples/{llamacpp-p2p.js → llamacpp-hyperdrive.js} +2 -1
- package/dist/examples/llamacpp-multimodal.js +4 -3
- package/dist/examples/llamacpp-native-tools.js +30 -72
- package/dist/examples/multi-model-demo.js +3 -2
- package/dist/examples/parallel-download.js +14 -46
- package/dist/examples/rag/rag-chromadb.js +1 -0
- package/dist/examples/rag/rag-hyperdb-workspaces.d.ts +2 -0
- package/dist/examples/rag/rag-hyperdb-workspaces.js +107 -0
- package/dist/examples/rag/rag-hyperdb.d.ts +2 -0
- package/dist/examples/rag/{rag-hyperdb/ingest.js → rag-hyperdb.js} +5 -10
- package/dist/examples/rag/rag-lancedb.js +1 -0
- package/dist/examples/rag/rag-sqlite.js +1 -0
- package/dist/examples/seed-hyperdrive.d.ts +2 -0
- package/dist/examples/text-to-speech.d.ts +3 -0
- package/dist/examples/{tts/utils.js → text-to-speech.js} +63 -18
- package/dist/examples/translation/translation-indic.js +1 -4
- package/dist/examples/translation/translation-llm-context.js +1 -0
- package/dist/examples/translation/translation-llm.js +2 -2
- package/dist/examples/translation/translation-opus.js +3 -6
- package/dist/examples/translation/translation-stream.js +3 -3
- package/dist/examples/whispercpp-filesystem.js +43 -0
- package/dist/examples/{transcription/whispercpp-microphone-record.js → whispercpp-microphone-record.js} +9 -8
- package/dist/expo/plugins/index.d.ts +0 -3
- package/dist/expo/plugins/index.js +0 -3
- package/dist/expo/plugins/withMobileBundle.d.ts +2 -5
- package/dist/expo/plugins/withMobileBundle.js +40 -121
- package/dist/expo/plugins/withQvacSDK.d.ts +0 -4
- package/dist/expo/plugins/withQvacSDK.js +1 -26
- package/dist/index.d.ts +4 -9
- package/dist/index.js +5 -11
- package/dist/logging/base-logger.js +16 -26
- package/dist/logging/index.d.ts +1 -7
- package/dist/logging/index.js +1 -7
- package/dist/logging/logger.d.ts +2 -0
- package/dist/logging/logger.js +6 -11
- package/dist/logging/stream-logger.d.ts +1 -1
- package/dist/logging/stream-logger.js +3 -6
- package/dist/logging/transport.js +2 -2
- package/dist/logging/types.d.ts +0 -2
- package/dist/logging/utils.d.ts +0 -2
- package/dist/logging/utils.js +0 -62
- package/dist/models/{registry → hyperdrive}/index.js +1 -1
- package/dist/models/hyperdrive/models.d.ts +619 -0
- package/dist/models/hyperdrive/models.js +693 -0
- package/dist/schemas/cancel.d.ts +0 -18
- package/dist/schemas/cancel.js +0 -7
- package/dist/schemas/common.d.ts +166 -3012
- package/dist/schemas/common.js +4 -27
- package/dist/schemas/completion-stream.d.ts +60 -31
- package/dist/schemas/completion-stream.js +44 -20
- package/dist/schemas/delegate.d.ts +0 -9
- package/dist/schemas/delegate.js +2 -6
- package/dist/schemas/download-asset.d.ts +3 -125
- package/dist/schemas/download-asset.js +5 -22
- package/dist/schemas/embed.d.ts +3 -3
- package/dist/schemas/embed.js +2 -9
- package/dist/schemas/index.d.ts +2 -20
- package/dist/schemas/index.js +2 -20
- package/dist/schemas/llamacpp-config.d.ts +12 -243
- package/dist/schemas/llamacpp-config.js +14 -50
- package/dist/schemas/load-model.d.ts +893 -14471
- package/dist/schemas/load-model.js +72 -325
- package/dist/schemas/logging-stream.d.ts +4 -11
- package/dist/schemas/logging-stream.js +3 -4
- package/dist/schemas/ping.d.ts +11 -0
- package/dist/schemas/ping.js +8 -0
- package/dist/schemas/rag.d.ts +52 -183
- package/dist/schemas/rag.js +23 -152
- package/dist/schemas/text-to-speech.d.ts +1 -692
- package/dist/schemas/text-to-speech.js +3 -35
- package/dist/schemas/transcription.d.ts +0 -3
- package/dist/schemas/transcription.js +0 -1
- package/dist/schemas/translate.d.ts +23 -68
- package/dist/schemas/translate.js +11 -37
- package/dist/schemas/translation-config.d.ts +7 -810
- package/dist/schemas/translation-config.js +7 -113
- package/dist/schemas/unload-model.d.ts +0 -2
- package/dist/schemas/unload-model.js +0 -2
- package/dist/schemas/whispercpp-config.d.ts +25 -0
- package/dist/schemas/whispercpp-config.js +18 -0
- package/dist/server/bare/{ops → addons}/cancel.js +1 -2
- package/dist/server/bare/addons/index.d.ts +4 -0
- package/dist/server/bare/addons/index.js +3 -0
- package/dist/server/bare/addons/llamacpp/create-model.d.ts +5 -0
- package/dist/server/bare/addons/llamacpp/create-model.js +67 -0
- package/dist/server/bare/{plugins/llamacpp-completion/ops → addons/llamacpp/handlers}/completion-stream.d.ts +1 -2
- package/dist/server/bare/{plugins/llamacpp-completion/ops → addons/llamacpp/handlers}/completion-stream.js +87 -54
- package/dist/server/bare/addons/llamacpp/handlers/embed.d.ts +4 -0
- package/dist/server/bare/{ops → addons/llamacpp/handlers}/embed.js +7 -22
- package/dist/server/bare/addons/llamacpp/index.d.ts +4 -0
- package/dist/server/bare/addons/llamacpp/index.js +3 -0
- package/dist/server/bare/{ops → addons/llamacpp}/kv-cache-utils.d.ts +1 -4
- package/dist/server/bare/{ops → addons/llamacpp}/kv-cache-utils.js +19 -54
- package/dist/server/bare/addons/load-model.d.ts +3 -0
- package/dist/server/bare/addons/load-model.js +62 -0
- package/dist/server/bare/addons/translation/create-model.d.ts +4 -0
- package/dist/server/bare/addons/translation/create-model.js +45 -0
- package/dist/server/bare/addons/translation/handlers/translate.d.ts +3 -0
- package/dist/server/bare/{ops → addons/translation/handlers}/translate.js +14 -47
- package/dist/server/bare/addons/translation/index.d.ts +3 -0
- package/dist/server/bare/addons/translation/index.js +2 -0
- package/dist/server/bare/addons/tts/create-model.d.ts +6 -0
- package/dist/server/bare/addons/tts/create-model.js +40 -0
- package/dist/server/bare/{plugins/onnx-tts/ops → addons/tts/handlers}/text-to-speech.js +3 -25
- package/dist/server/bare/addons/tts/index.d.ts +3 -0
- package/dist/server/bare/addons/tts/index.js +2 -0
- package/dist/server/bare/addons/unload-model.js +20 -0
- package/dist/server/bare/addons/whispercpp/create-model.d.ts +6 -0
- package/dist/server/bare/addons/whispercpp/create-model.js +55 -0
- package/dist/server/bare/addons/whispercpp/handlers/transcribe-stream.d.ts +3 -0
- package/dist/server/bare/addons/whispercpp/handlers/transcribe-stream.js +48 -0
- package/dist/server/bare/addons/whispercpp/index.d.ts +3 -0
- package/dist/server/bare/addons/whispercpp/index.js +2 -0
- package/dist/server/bare/delegate-rpc-client.d.ts +0 -6
- package/dist/server/bare/delegate-rpc-client.js +45 -187
- package/dist/server/bare/hyperswarm.d.ts +0 -3
- package/dist/server/bare/hyperswarm.js +6 -29
- package/dist/server/bare/rag-hyperdb/handlers/delete-embeddings.d.ts +1 -1
- package/dist/server/bare/rag-hyperdb/handlers/delete-embeddings.js +10 -9
- package/dist/server/bare/rag-hyperdb/handlers/save-embeddings.d.ts +4 -7
- package/dist/server/bare/rag-hyperdb/handlers/save-embeddings.js +14 -13
- package/dist/server/bare/rag-hyperdb/handlers/search.js +10 -10
- package/dist/server/bare/rag-hyperdb/index.d.ts +1 -8
- package/dist/server/bare/rag-hyperdb/index.js +1 -8
- package/dist/server/bare/rag-hyperdb/rag-manager.d.ts +5 -0
- package/dist/server/bare/rag-hyperdb/rag-manager.js +65 -0
- package/dist/server/bare/registry/logging-stream-registry.d.ts +7 -24
- package/dist/server/bare/registry/logging-stream-registry.js +20 -99
- package/dist/server/bare/registry/model-registry.d.ts +26 -16
- package/dist/server/bare/registry/model-registry.js +13 -34
- package/dist/server/error-handlers.d.ts +2 -3
- package/dist/server/error-handlers.js +10 -15
- package/dist/server/http-server.d.ts +2 -0
- package/dist/server/http-server.js +189 -0
- package/dist/server/rpc/create-server.js +3 -5
- package/dist/server/rpc/handle-request.d.ts +9 -0
- package/dist/server/rpc/handle-request.js +242 -92
- package/dist/server/rpc/handlers/cancelHandler.js +3 -14
- package/dist/server/rpc/handlers/completion-stream-delegated.d.ts +1 -3
- package/dist/server/rpc/handlers/completion-stream-delegated.js +8 -20
- package/dist/server/rpc/handlers/completion-stream.js +41 -2
- package/dist/server/rpc/handlers/delete-cache.js +2 -4
- package/dist/server/rpc/handlers/download-asset.js +6 -59
- package/dist/server/rpc/handlers/embed.js +19 -2
- package/dist/server/rpc/handlers/index.d.ts +0 -13
- package/dist/server/rpc/handlers/index.js +0 -13
- package/dist/server/rpc/handlers/load-model/download-manager.d.ts +11 -12
- package/dist/server/rpc/handlers/load-model/download-manager.js +28 -43
- package/dist/server/rpc/handlers/load-model/http.d.ts +1 -2
- package/dist/server/rpc/handlers/load-model/http.js +55 -424
- package/dist/server/rpc/handlers/load-model/hyperdrive.d.ts +1 -2
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +171 -364
- 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.d.ts +1 -3
- package/dist/server/rpc/handlers/load-model/resolve.js +29 -110
- package/dist/server/rpc/handlers/load-model-delegated.d.ts +2 -6
- package/dist/server/rpc/handlers/load-model-delegated.js +20 -60
- package/dist/server/rpc/handlers/{load-model/handler.d.ts → load-model.d.ts} +2 -2
- package/dist/server/rpc/handlers/load-model.js +57 -0
- package/dist/server/rpc/handlers/logging-stream.js +4 -4
- package/dist/server/rpc/handlers/provideHandler/connection.js +10 -12
- package/dist/server/rpc/handlers/provideHandler/handler.js +17 -20
- package/dist/server/rpc/handlers/provideHandler/proxy.js +6 -8
- package/dist/server/rpc/handlers/rag.d.ts +2 -2
- package/dist/server/rpc/handlers/rag.js +43 -130
- package/dist/server/rpc/handlers/stopProvideHandler.js +2 -6
- package/dist/server/rpc/handlers/text-to-speech.js +5 -2
- package/dist/server/rpc/handlers/transcribe-stream.js +24 -2
- package/dist/server/rpc/handlers/translate.js +49 -2
- package/dist/server/rpc/handlers/unload-model.js +3 -12
- package/dist/server/rpc/index.d.ts +1 -1
- package/dist/server/utils/audio/decoder.d.ts +1 -2
- package/dist/server/utils/audio/decoder.js +12 -49
- package/dist/server/utils/cache.d.ts +8 -19
- package/dist/server/utils/cache.js +15 -100
- package/dist/server/utils/hash.d.ts +5 -0
- package/dist/server/utils/hash.js +11 -0
- package/dist/server/utils/index.d.ts +2 -7
- package/dist/server/utils/index.js +2 -7
- package/dist/server/utils/tool-parser.js +14 -28
- package/dist/server/worker.d.ts +5 -4
- package/dist/server/worker.js +89 -22
- package/package.json +41 -148
- package/NOTICE +0 -695
- package/bare-imports.json +0 -44
- package/dist/client/api/get-model-info.d.ts +0 -36
- package/dist/client/api/get-model-info.js +0 -14
- package/dist/client/api/heartbeat.d.ts +0 -30
- package/dist/client/api/heartbeat.js +0 -38
- package/dist/client/api/invoke-plugin.d.ts +0 -15
- package/dist/client/api/invoke-plugin.js +0 -38
- package/dist/client/api/ocr.d.ts +0 -31
- package/dist/client/api/ocr.js +0 -88
- package/dist/client/api/registry.d.ts +0 -14
- package/dist/client/api/registry.js +0 -37
- package/dist/client/config-loader/config-utils.d.ts +0 -5
- package/dist/client/config-loader/config-utils.js +0 -20
- package/dist/client/config-loader/resolve-config.bare.d.ts +0 -9
- package/dist/client/config-loader/resolve-config.bare.js +0 -87
- package/dist/client/config-loader/resolve-config.expo.d.ts +0 -11
- package/dist/client/config-loader/resolve-config.expo.js +0 -62
- package/dist/client/config-loader/resolve-config.node.d.ts +0 -10
- package/dist/client/config-loader/resolve-config.node.js +0 -145
- package/dist/client/init-hooks.d.ts +0 -21
- package/dist/client/init-hooks.js +0 -66
- package/dist/client/rpc/expo-device-info.d.ts +0 -6
- package/dist/client/rpc/expo-device-info.js +0 -32
- package/dist/client/rpc/profiling/index.d.ts +0 -2
- package/dist/client/rpc/profiling/index.js +0 -1
- package/dist/client/rpc/profiling/profiler.d.ts +0 -27
- package/dist/client/rpc/profiling/profiler.js +0 -139
- package/dist/constants/registry.d.ts +0 -2
- package/dist/constants/registry.js +0 -1
- package/dist/examples/cache-management.d.ts +0 -2
- package/dist/examples/cache-management.js +0 -97
- package/dist/examples/config/blind-relay/blind-relay.config.d.ts +0 -5
- package/dist/examples/config/blind-relay/blind-relay.config.js +0 -7
- package/dist/examples/config/default/default.config.d.ts +0 -8
- package/dist/examples/config/default/default.config.js +0 -6
- package/dist/examples/config/plugins/plugins.config.d.ts +0 -5
- package/dist/examples/config/plugins/plugins.config.js +0 -4
- package/dist/examples/config-reload.d.ts +0 -2
- package/dist/examples/config-reload.js +0 -49
- package/dist/examples/default-config-usage.d.ts +0 -17
- package/dist/examples/default-config-usage.js +0 -47
- package/dist/examples/delegated-inference/consumer-profiled.d.ts +0 -2
- package/dist/examples/delegated-inference/consumer-profiled.js +0 -67
- package/dist/examples/download-with-blind-relays.d.ts +0 -2
- package/dist/examples/download-with-blind-relays.js +0 -49
- package/dist/examples/embed-p2p.d.ts +0 -2
- package/dist/examples/embed-p2p.js +0 -54
- package/dist/examples/llamacpp-p2p.d.ts +0 -2
- package/dist/examples/llamacpp-sharded.d.ts +0 -2
- package/dist/examples/llamacpp-sharded.js +0 -53
- package/dist/examples/logging-file-transport.d.ts +0 -2
- package/dist/examples/logging-streaming.d.ts +0 -2
- package/dist/examples/logging-streaming.js +0 -75
- package/dist/examples/mcp-websearch.d.ts +0 -13
- package/dist/examples/mcp-websearch.js +0 -176
- package/dist/examples/ocr-fasttext.d.ts +0 -2
- package/dist/examples/ocr-fasttext.js +0 -52
- package/dist/examples/plugins.d.ts +0 -14
- package/dist/examples/plugins.js +0 -129
- package/dist/examples/profiling/basic.d.ts +0 -2
- package/dist/examples/profiling/basic.js +0 -71
- package/dist/examples/profiling/per-call.d.ts +0 -2
- package/dist/examples/profiling/per-call.js +0 -30
- package/dist/examples/quickstart.d.ts +0 -2
- package/dist/examples/quickstart.js +0 -28
- package/dist/examples/rag/rag-hyperdb/cancellation.d.ts +0 -2
- package/dist/examples/rag/rag-hyperdb/cancellation.js +0 -75
- package/dist/examples/rag/rag-hyperdb/ingest.d.ts +0 -2
- package/dist/examples/rag/rag-hyperdb/pipeline.d.ts +0 -2
- package/dist/examples/rag/rag-hyperdb/pipeline.js +0 -74
- package/dist/examples/rag/rag-hyperdb/workspaces.d.ts +0 -2
- package/dist/examples/rag/rag-hyperdb/workspaces.js +0 -178
- package/dist/examples/registry-query.d.ts +0 -2
- package/dist/examples/registry-query.js +0 -87
- package/dist/examples/seed-p2p.d.ts +0 -2
- package/dist/examples/transcription/parakeet-ctc-filesystem.d.ts +0 -2
- package/dist/examples/transcription/parakeet-ctc-filesystem.js +0 -40
- package/dist/examples/transcription/parakeet-microphone-record.d.ts +0 -2
- package/dist/examples/transcription/parakeet-microphone-record.js +0 -95
- package/dist/examples/transcription/parakeet-sortformer.d.ts +0 -2
- package/dist/examples/transcription/parakeet-sortformer.js +0 -115
- package/dist/examples/transcription/parakeet-tdt-filesystem.d.ts +0 -2
- package/dist/examples/transcription/parakeet-tdt-filesystem.js +0 -44
- package/dist/examples/transcription/whispercpp-filesystem.js +0 -69
- package/dist/examples/transcription/whispercpp-prompt.d.ts +0 -2
- package/dist/examples/transcription/whispercpp-prompt.js +0 -67
- package/dist/examples/translation/translation-bergamot-batch.d.ts +0 -2
- package/dist/examples/translation/translation-bergamot-batch.js +0 -49
- package/dist/examples/translation/translation-bergamot-pivot.d.ts +0 -2
- package/dist/examples/translation/translation-bergamot-pivot.js +0 -73
- package/dist/examples/translation/translation-bergamot.d.ts +0 -2
- package/dist/examples/translation/translation-bergamot.js +0 -39
- package/dist/examples/translation/translation-llm-afriquegemma.d.ts +0 -2
- package/dist/examples/translation/translation-llm-afriquegemma.js +0 -39
- package/dist/examples/tts/chatterbox.d.ts +0 -2
- package/dist/examples/tts/chatterbox.js +0 -59
- package/dist/examples/tts/supertonic.d.ts +0 -2
- package/dist/examples/tts/supertonic.js +0 -51
- package/dist/examples/tts/utils.d.ts +0 -17
- package/dist/expo/plugins/resolve-sdk-package-dir.d.ts +0 -15
- package/dist/expo/plugins/resolve-sdk-package-dir.js +0 -31
- package/dist/expo/plugins/withAndroidArchitecture.d.ts +0 -8
- package/dist/expo/plugins/withAndroidArchitecture.js +0 -52
- package/dist/expo/plugins/withAndroidNdkVersion.d.ts +0 -8
- package/dist/expo/plugins/withAndroidNdkVersion.js +0 -31
- package/dist/expo/plugins/withDeviceInfo.d.ts +0 -10
- package/dist/expo/plugins/withDeviceInfo.js +0 -48
- package/dist/logging/addon.d.ts +0 -6
- package/dist/logging/addon.js +0 -75
- package/dist/logging/client-logger.d.ts +0 -3
- package/dist/logging/client-logger.js +0 -24
- package/dist/logging/namespaces.d.ts +0 -6
- package/dist/logging/namespaces.js +0 -6
- package/dist/logging/registry.d.ts +0 -31
- package/dist/logging/registry.js +0 -62
- package/dist/logging/server-logger.d.ts +0 -3
- package/dist/logging/server-logger.js +0 -16
- package/dist/models/registry/models.d.ts +0 -10417
- package/dist/models/registry/models.js +0 -10757
- package/dist/models/update-models/codegen.d.ts +0 -3
- package/dist/models/update-models/codegen.js +0 -135
- package/dist/models/update-models/history.d.ts +0 -24
- package/dist/models/update-models/history.js +0 -107
- package/dist/models/update-models/index.d.ts +0 -2
- package/dist/models/update-models/index.js +0 -125
- package/dist/models/update-models/naming.d.ts +0 -4
- package/dist/models/update-models/naming.js +0 -370
- package/dist/models/update-models/processing.d.ts +0 -8
- package/dist/models/update-models/processing.js +0 -67
- package/dist/models/update-models/registry.d.ts +0 -4
- package/dist/models/update-models/registry.js +0 -67
- package/dist/models/update-models/shards.d.ts +0 -4
- package/dist/models/update-models/shards.js +0 -57
- package/dist/models/update-models/types.d.ts +0 -60
- package/dist/models/update-models/types.js +0 -1
- package/dist/models/update-models/utils.d.ts +0 -3
- package/dist/models/update-models/utils.js +0 -21
- package/dist/pear/pre.d.ts +0 -18
- package/dist/pear/pre.js +0 -433
- package/dist/profiling/aggregator.d.ts +0 -15
- package/dist/profiling/aggregator.js +0 -100
- package/dist/profiling/clock.d.ts +0 -12
- package/dist/profiling/clock.js +0 -51
- package/dist/profiling/controller.d.ts +0 -33
- package/dist/profiling/controller.js +0 -123
- package/dist/profiling/envelope.d.ts +0 -10
- package/dist/profiling/envelope.js +0 -36
- package/dist/profiling/events.d.ts +0 -20
- package/dist/profiling/events.js +0 -37
- package/dist/profiling/exporters.d.ts +0 -10
- package/dist/profiling/exporters.js +0 -236
- package/dist/profiling/index.d.ts +0 -36
- package/dist/profiling/index.js +0 -31
- package/dist/profiling/ring-buffer.d.ts +0 -19
- package/dist/profiling/ring-buffer.js +0 -83
- package/dist/profiling/types.d.ts +0 -47
- package/dist/profiling/types.js +0 -1
- package/dist/schemas/archive.d.ts +0 -9
- package/dist/schemas/archive.js +0 -17
- package/dist/schemas/engine-addon-map.d.ts +0 -5
- package/dist/schemas/engine-addon-map.js +0 -52
- package/dist/schemas/get-model-info.d.ts +0 -120
- package/dist/schemas/get-model-info.js +0 -58
- package/dist/schemas/heartbeat.d.ts +0 -17
- package/dist/schemas/heartbeat.js +0 -10
- package/dist/schemas/json-schema.d.ts +0 -16
- package/dist/schemas/json-schema.js +0 -2
- package/dist/schemas/mcp-adapter.d.ts +0 -47
- package/dist/schemas/mcp-adapter.js +0 -1
- package/dist/schemas/model-src-utils.d.ts +0 -148
- package/dist/schemas/model-src-utils.js +0 -35
- package/dist/schemas/model-types.d.ts +0 -183
- package/dist/schemas/model-types.js +0 -168
- package/dist/schemas/ocr.d.ts +0 -125
- package/dist/schemas/ocr.js +0 -57
- package/dist/schemas/path-validation.d.ts +0 -10
- package/dist/schemas/path-validation.js +0 -22
- package/dist/schemas/plugin.d.ts +0 -226
- package/dist/schemas/plugin.js +0 -158
- package/dist/schemas/profiling.d.ts +0 -105
- package/dist/schemas/profiling.js +0 -66
- package/dist/schemas/registry.d.ts +0 -356
- package/dist/schemas/registry.js +0 -93
- package/dist/schemas/reload-config.d.ts +0 -476
- package/dist/schemas/reload-config.js +0 -44
- package/dist/schemas/runtime-context.d.ts +0 -19
- package/dist/schemas/runtime-context.js +0 -7
- package/dist/schemas/sdk-config.d.ts +0 -2973
- package/dist/schemas/sdk-config.js +0 -136
- package/dist/schemas/sdk-errors-client.d.ts +0 -31
- package/dist/schemas/sdk-errors-client.js +0 -143
- package/dist/schemas/sdk-errors-registry.d.ts +0 -6
- package/dist/schemas/sdk-errors-registry.js +0 -8
- package/dist/schemas/sdk-errors-server.d.ts +0 -89
- package/dist/schemas/sdk-errors-server.js +0 -451
- package/dist/schemas/shard.d.ts +0 -21
- package/dist/schemas/shard.js +0 -17
- package/dist/schemas/tools.d.ts +0 -65
- package/dist/schemas/tools.js +0 -43
- package/dist/schemas/transcription-config.d.ts +0 -383
- package/dist/schemas/transcription-config.js +0 -95
- package/dist/scripts/run-security-tests-bare.d.ts +0 -2
- package/dist/scripts/run-security-tests-bare.js +0 -78
- package/dist/scripts/run-security-tests.d.ts +0 -2
- package/dist/scripts/run-security-tests.js +0 -22
- package/dist/scripts/run-unit-tests.d.ts +0 -2
- package/dist/scripts/run-unit-tests.js +0 -17
- package/dist/server/bare/ops/embed.d.ts +0 -12
- package/dist/server/bare/ops/load-model.d.ts +0 -9
- package/dist/server/bare/ops/load-model.js +0 -85
- package/dist/server/bare/ops/transcribe.d.ts +0 -3
- package/dist/server/bare/ops/transcribe.js +0 -75
- package/dist/server/bare/ops/translate.d.ts +0 -5
- package/dist/server/bare/ops/unload-model.js +0 -41
- package/dist/server/bare/plugins/index.d.ts +0 -8
- package/dist/server/bare/plugins/index.js +0 -7
- package/dist/server/bare/plugins/llamacpp-completion/ops/cache-logger.d.ts +0 -6
- package/dist/server/bare/plugins/llamacpp-completion/ops/cache-logger.js +0 -34
- package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +0 -220
- package/dist/server/bare/plugins/llamacpp-completion/plugin.js +0 -155
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.d.ts +0 -54
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.js +0 -87
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +0 -367
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.js +0 -201
- package/dist/server/bare/plugins/onnx-ocr/ops/ocr-stream.d.ts +0 -10
- package/dist/server/bare/plugins/onnx-ocr/ops/ocr-stream.js +0 -110
- package/dist/server/bare/plugins/onnx-ocr/plugin.d.ts +0 -86
- package/dist/server/bare/plugins/onnx-ocr/plugin.js +0 -117
- package/dist/server/bare/plugins/onnx-tts/plugin.d.ts +0 -373
- package/dist/server/bare/plugins/onnx-tts/plugin.js +0 -182
- package/dist/server/bare/plugins/onnx-tts/wav-helper.d.ts +0 -14
- package/dist/server/bare/plugins/onnx-tts/wav-helper.js +0 -107
- package/dist/server/bare/plugins/parakeet-transcription/plugin.d.ts +0 -317
- package/dist/server/bare/plugins/parakeet-transcription/plugin.js +0 -154
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +0 -237
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +0 -86
- package/dist/server/bare/rag-hyperdb/handlers/chunk.d.ts +0 -3
- package/dist/server/bare/rag-hyperdb/handlers/chunk.js +0 -7
- package/dist/server/bare/rag-hyperdb/handlers/close-workspace.d.ts +0 -3
- package/dist/server/bare/rag-hyperdb/handlers/close-workspace.js +0 -9
- package/dist/server/bare/rag-hyperdb/handlers/delete-workspace.d.ts +0 -3
- package/dist/server/bare/rag-hyperdb/handlers/delete-workspace.js +0 -14
- package/dist/server/bare/rag-hyperdb/handlers/ingest.d.ts +0 -9
- package/dist/server/bare/rag-hyperdb/handlers/ingest.js +0 -18
- package/dist/server/bare/rag-hyperdb/handlers/list-workspaces.d.ts +0 -3
- package/dist/server/bare/rag-hyperdb/handlers/list-workspaces.js +0 -4
- package/dist/server/bare/rag-hyperdb/handlers/reindex.d.ts +0 -9
- package/dist/server/bare/rag-hyperdb/handlers/reindex.js +0 -16
- package/dist/server/bare/rag-hyperdb/rag-operation-manager.d.ts +0 -7
- package/dist/server/bare/rag-hyperdb/rag-operation-manager.js +0 -39
- package/dist/server/bare/rag-hyperdb/rag-workspace-manager.d.ts +0 -15
- package/dist/server/bare/rag-hyperdb/rag-workspace-manager.js +0 -136
- package/dist/server/bare/registry/config-registry.d.ts +0 -14
- package/dist/server/bare/registry/config-registry.js +0 -82
- package/dist/server/bare/registry/model-config-registry.d.ts +0 -4
- package/dist/server/bare/registry/model-config-registry.js +0 -15
- package/dist/server/bare/registry/model-config-utils.d.ts +0 -15
- package/dist/server/bare/registry/model-config-utils.js +0 -112
- package/dist/server/bare/registry/registry-client.d.ts +0 -5
- package/dist/server/bare/registry/registry-client.js +0 -37
- package/dist/server/bare/registry/runtime-context-registry.d.ts +0 -7
- package/dist/server/bare/registry/runtime-context-registry.js +0 -26
- package/dist/server/bare/utils/audio-input.d.ts +0 -10
- package/dist/server/bare/utils/audio-input.js +0 -33
- package/dist/server/bare/utils/loader-adapter.d.ts +0 -7
- package/dist/server/bare/utils/loader-adapter.js +0 -9
- package/dist/server/env.d.ts +0 -22
- package/dist/server/env.js +0 -57
- package/dist/server/plugins/index.d.ts +0 -2
- package/dist/server/plugins/index.js +0 -1
- package/dist/server/plugins/registry.d.ts +0 -9
- package/dist/server/plugins/registry.js +0 -79
- package/dist/server/rpc/delegate-transport.d.ts +0 -19
- package/dist/server/rpc/delegate-transport.js +0 -236
- package/dist/server/rpc/delegate-utils.d.ts +0 -2
- package/dist/server/rpc/delegate-utils.js +0 -5
- package/dist/server/rpc/handler-registry.d.ts +0 -3
- package/dist/server/rpc/handler-registry.js +0 -113
- package/dist/server/rpc/handler-utils.d.ts +0 -23
- package/dist/server/rpc/handler-utils.js +0 -170
- package/dist/server/rpc/handlers/cancel-delegated.d.ts +0 -4
- package/dist/server/rpc/handlers/cancel-delegated.js +0 -71
- package/dist/server/rpc/handlers/get-model-info.d.ts +0 -3
- package/dist/server/rpc/handlers/get-model-info.js +0 -164
- package/dist/server/rpc/handlers/heartbeat-delegated.d.ts +0 -4
- package/dist/server/rpc/handlers/heartbeat-delegated.js +0 -32
- package/dist/server/rpc/handlers/heartbeat.d.ts +0 -3
- package/dist/server/rpc/handlers/heartbeat.js +0 -3
- package/dist/server/rpc/handlers/load-model/download-stats.d.ts +0 -6
- package/dist/server/rpc/handlers/load-model/download-stats.js +0 -87
- package/dist/server/rpc/handlers/load-model/handler.js +0 -187
- package/dist/server/rpc/handlers/load-model/registry.d.ts +0 -11
- package/dist/server/rpc/handlers/load-model/registry.js +0 -548
- package/dist/server/rpc/handlers/load-model/types.d.ts +0 -29
- package/dist/server/rpc/handlers/load-model/types.js +0 -1
- package/dist/server/rpc/handlers/ocr-stream.d.ts +0 -3
- package/dist/server/rpc/handlers/ocr-stream.js +0 -4
- package/dist/server/rpc/handlers/plugin-dispatch.d.ts +0 -15
- package/dist/server/rpc/handlers/plugin-dispatch.js +0 -59
- package/dist/server/rpc/handlers/plugin-invoke.d.ts +0 -4
- package/dist/server/rpc/handlers/plugin-invoke.js +0 -92
- package/dist/server/rpc/handlers/registry.d.ts +0 -5
- package/dist/server/rpc/handlers/registry.js +0 -157
- package/dist/server/rpc/handlers/unload-model-delegated.d.ts +0 -3
- package/dist/server/rpc/handlers/unload-model-delegated.js +0 -32
- package/dist/server/rpc/profiling/context.d.ts +0 -18
- package/dist/server/rpc/profiling/context.js +0 -38
- package/dist/server/rpc/profiling/delegation-profiler.d.ts +0 -32
- package/dist/server/rpc/profiling/delegation-profiler.js +0 -154
- package/dist/server/rpc/profiling/index.d.ts +0 -5
- package/dist/server/rpc/profiling/index.js +0 -4
- package/dist/server/rpc/profiling/operation-metrics.d.ts +0 -25
- package/dist/server/rpc/profiling/operation-metrics.js +0 -199
- package/dist/server/rpc/profiling/operation-wrappers.d.ts +0 -18
- package/dist/server/rpc/profiling/operation-wrappers.js +0 -124
- package/dist/server/rpc/profiling/profiler.d.ts +0 -13
- package/dist/server/rpc/profiling/profiler.js +0 -97
- package/dist/server/utils/archive.d.ts +0 -4
- package/dist/server/utils/archive.js +0 -179
- package/dist/server/utils/checksum.d.ts +0 -4
- package/dist/server/utils/checksum.js +0 -31
- package/dist/server/utils/config-transform.d.ts +0 -3
- package/dist/server/utils/config-transform.js +0 -23
- package/dist/server/utils/formatting.d.ts +0 -19
- package/dist/server/utils/formatting.js +0 -61
- package/dist/server/utils/gguf-tensor-extractor.d.ts +0 -15
- package/dist/server/utils/gguf-tensor-extractor.js +0 -314
- package/dist/server/utils/path-security.d.ts +0 -12
- package/dist/server/utils/path-security.js +0 -25
- package/dist/server/utils/shard-utils.d.ts +0 -48
- package/dist/server/utils/shard-utils.js +0 -125
- package/dist/server/utils/tool-integration.d.ts +0 -13
- package/dist/server/utils/tool-integration.js +0 -43
- package/dist/server/worker-core.d.ts +0 -6
- package/dist/server/worker-core.js +0 -88
- package/dist/utils/errors-base.d.ts +0 -3
- package/dist/utils/errors-base.js +0 -13
- package/dist/utils/errors-client.d.ts +0 -137
- package/dist/utils/errors-client.js +0 -240
- package/dist/utils/errors-server.d.ts +0 -236
- package/dist/utils/errors-server.js +0 -412
- package/dist/utils/global-singleton.d.ts +0 -2
- package/dist/utils/global-singleton.js +0 -10
- package/dist/utils/mcp-adapter.d.ts +0 -12
- package/dist/utils/mcp-adapter.js +0 -103
- package/dist/utils/object.d.ts +0 -2
- package/dist/utils/object.js +0 -3
- package/dist/utils/path-sanitize.d.ts +0 -17
- package/dist/utils/path-sanitize.js +0 -54
- package/dist/utils/tool-helpers.d.ts +0 -25
- package/dist/utils/tool-helpers.js +0 -112
- package/expo/plugins/patches/android-link.mjs +0 -63
- package/expo/plugins/patches/ios-link.mjs +0 -63
- /package/dist/examples/{seed-p2p.js → seed-hyperdrive.js} +0 -0
- /package/dist/examples/{transcription/whispercpp-filesystem.d.ts → whispercpp-filesystem.d.ts} +0 -0
- /package/dist/examples/{transcription/whispercpp-microphone-record.d.ts → whispercpp-microphone-record.d.ts} +0 -0
- /package/dist/models/{registry → hyperdrive}/index.d.ts +0 -0
- /package/dist/server/bare/{ops → addons}/cancel.d.ts +0 -0
- /package/dist/server/bare/{plugins/onnx-tts/ops → addons/tts/handlers}/text-to-speech.d.ts +0 -0
- /package/dist/server/bare/{ops → addons}/unload-model.d.ts +0 -0
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Central state management for profiling enablement, configuration, and recording.
|
|
3
|
-
*
|
|
4
|
-
* Precedence (highest to lowest):
|
|
5
|
-
* 1. Per-call override
|
|
6
|
-
* 2. Runtime API (enable/disable)
|
|
7
|
-
* 3. Disabled default
|
|
8
|
-
*/
|
|
9
|
-
import { getGlobalSingleton } from "../utils/global-singleton.js";
|
|
10
|
-
import { createAggregator, recordEvent as aggregatorRecord, getAggregates as aggregatorGetAggregates, getRecentEvents as aggregatorGetRecentEvents, clearAggregator, setMaxRecentEvents, } from "./aggregator.js";
|
|
11
|
-
import { nowMs, generateProfileId } from "./clock.js";
|
|
12
|
-
const DEFAULT_CONFIG = {
|
|
13
|
-
enabled: false,
|
|
14
|
-
mode: "summary",
|
|
15
|
-
includeServerBreakdown: false,
|
|
16
|
-
operationFilters: [],
|
|
17
|
-
maxRecentEvents: 1000,
|
|
18
|
-
};
|
|
19
|
-
const CONTROLLER_STATE_KEY = Symbol.for("@qvac/sdk:profiler-controller-state");
|
|
20
|
-
function getControllerState() {
|
|
21
|
-
const state = getGlobalSingleton(CONTROLLER_STATE_KEY, () => {
|
|
22
|
-
return {
|
|
23
|
-
runtimeOverride: undefined,
|
|
24
|
-
runtimeOptions: {},
|
|
25
|
-
onRecordCallbacks: [],
|
|
26
|
-
initialized: false,
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
if (!state.initialized) {
|
|
30
|
-
createAggregator(DEFAULT_CONFIG.maxRecentEvents);
|
|
31
|
-
state.initialized = true;
|
|
32
|
-
}
|
|
33
|
-
return state;
|
|
34
|
-
}
|
|
35
|
-
export function enable(options) {
|
|
36
|
-
const state = getControllerState();
|
|
37
|
-
state.runtimeOverride = true;
|
|
38
|
-
state.runtimeOptions = options ? { ...options } : {};
|
|
39
|
-
clearAggregator();
|
|
40
|
-
setMaxRecentEvents(DEFAULT_CONFIG.maxRecentEvents);
|
|
41
|
-
}
|
|
42
|
-
export function disable() {
|
|
43
|
-
const state = getControllerState();
|
|
44
|
-
state.runtimeOverride = false;
|
|
45
|
-
state.runtimeOptions = {};
|
|
46
|
-
setMaxRecentEvents(DEFAULT_CONFIG.maxRecentEvents);
|
|
47
|
-
}
|
|
48
|
-
export function isEnabled() {
|
|
49
|
-
const state = getControllerState();
|
|
50
|
-
return state.runtimeOverride ?? false;
|
|
51
|
-
}
|
|
52
|
-
export function getEffectiveConfig() {
|
|
53
|
-
const state = getControllerState();
|
|
54
|
-
return {
|
|
55
|
-
enabled: isEnabled(),
|
|
56
|
-
mode: state.runtimeOptions.mode ?? DEFAULT_CONFIG.mode,
|
|
57
|
-
includeServerBreakdown: state.runtimeOptions.includeServerBreakdown ??
|
|
58
|
-
DEFAULT_CONFIG.includeServerBreakdown,
|
|
59
|
-
operationFilters: [
|
|
60
|
-
...(state.runtimeOptions.operationFilters ?? DEFAULT_CONFIG.operationFilters),
|
|
61
|
-
],
|
|
62
|
-
maxRecentEvents: DEFAULT_CONFIG.maxRecentEvents,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
export function shouldProfile(operation, perCallOptions) {
|
|
66
|
-
if (perCallOptions?.enabled !== undefined) {
|
|
67
|
-
return perCallOptions.enabled;
|
|
68
|
-
}
|
|
69
|
-
if (!isEnabled()) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
const config = getEffectiveConfig();
|
|
73
|
-
if (config.operationFilters.length > 0) {
|
|
74
|
-
return config.operationFilters.includes(operation);
|
|
75
|
-
}
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
export function shouldIncludeServerBreakdown(perCallOptions) {
|
|
79
|
-
if (perCallOptions?.includeServerBreakdown !== undefined) {
|
|
80
|
-
return perCallOptions.includeServerBreakdown;
|
|
81
|
-
}
|
|
82
|
-
return getEffectiveConfig().includeServerBreakdown;
|
|
83
|
-
}
|
|
84
|
-
export function generateId() {
|
|
85
|
-
return generateProfileId();
|
|
86
|
-
}
|
|
87
|
-
export function record(event) {
|
|
88
|
-
const state = getControllerState();
|
|
89
|
-
let eventWithTs = event;
|
|
90
|
-
if (event.ts === undefined) {
|
|
91
|
-
eventWithTs = { ...event, ts: nowMs() };
|
|
92
|
-
}
|
|
93
|
-
const storeInBuffer = getEffectiveConfig().mode === "verbose";
|
|
94
|
-
aggregatorRecord(eventWithTs, storeInBuffer);
|
|
95
|
-
for (const cb of state.onRecordCallbacks) {
|
|
96
|
-
try {
|
|
97
|
-
cb(eventWithTs);
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
// Callback errors should not break profiling
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/** Returns unsubscribe function. */
|
|
105
|
-
export function onRecord(callback) {
|
|
106
|
-
const state = getControllerState();
|
|
107
|
-
state.onRecordCallbacks.push(callback);
|
|
108
|
-
return () => {
|
|
109
|
-
const idx = state.onRecordCallbacks.indexOf(callback);
|
|
110
|
-
if (idx >= 0) {
|
|
111
|
-
state.onRecordCallbacks.splice(idx, 1);
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
export function getAggregates() {
|
|
116
|
-
return aggregatorGetAggregates();
|
|
117
|
-
}
|
|
118
|
-
export function getRecentEvents() {
|
|
119
|
-
return aggregatorGetRecentEvents();
|
|
120
|
-
}
|
|
121
|
-
export function clear() {
|
|
122
|
-
clearAggregator();
|
|
123
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helpers to inject/extract __profiling metadata in RPC payloads.
|
|
3
|
-
*/
|
|
4
|
-
import { type ProfilingRequestMeta, type ProfilingResponseMeta } from "../schemas/index";
|
|
5
|
-
export declare function createProfilingMeta(profileId: string, includeServerBreakdown: boolean): ProfilingRequestMeta;
|
|
6
|
-
export declare function createProfilingDisabledMeta(): ProfilingRequestMeta;
|
|
7
|
-
export declare function injectProfilingMetaIntoObject(obj: Record<string, unknown>, meta: ProfilingRequestMeta): Record<string, unknown>;
|
|
8
|
-
export declare function extractProfilingMeta(payload: unknown): ProfilingResponseMeta | undefined;
|
|
9
|
-
export declare function stripProfilingMeta<T extends object>(payload: T): T;
|
|
10
|
-
//# sourceMappingURL=envelope.d.ts.map
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helpers to inject/extract __profiling metadata in RPC payloads.
|
|
3
|
-
*/
|
|
4
|
-
import { PROFILING_KEY, } from "../schemas/index.js";
|
|
5
|
-
export function createProfilingMeta(profileId, includeServerBreakdown) {
|
|
6
|
-
return {
|
|
7
|
-
enabled: true,
|
|
8
|
-
id: profileId,
|
|
9
|
-
includeServer: includeServerBreakdown,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
export function createProfilingDisabledMeta() {
|
|
13
|
-
return { enabled: false };
|
|
14
|
-
}
|
|
15
|
-
export function injectProfilingMetaIntoObject(obj, meta) {
|
|
16
|
-
return { ...obj, [PROFILING_KEY]: meta };
|
|
17
|
-
}
|
|
18
|
-
export function extractProfilingMeta(payload) {
|
|
19
|
-
if (typeof payload === "object" &&
|
|
20
|
-
payload !== null &&
|
|
21
|
-
PROFILING_KEY in payload) {
|
|
22
|
-
const meta = payload[PROFILING_KEY];
|
|
23
|
-
if (typeof meta === "object" && meta !== null) {
|
|
24
|
-
return meta;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
export function stripProfilingMeta(payload) {
|
|
30
|
-
if (PROFILING_KEY in payload) {
|
|
31
|
-
const { [PROFILING_KEY]: _unused, ...rest } = payload;
|
|
32
|
-
void _unused;
|
|
33
|
-
return rest;
|
|
34
|
-
}
|
|
35
|
-
return payload;
|
|
36
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { ProfilingEventKind } from "./types";
|
|
2
|
-
import type { ServerBreakdown, DelegationBreakdown } from "../schemas/index";
|
|
3
|
-
export interface BaseTimings {
|
|
4
|
-
profileId: string;
|
|
5
|
-
requestType: string;
|
|
6
|
-
requestStart: number;
|
|
7
|
-
}
|
|
8
|
-
export interface BaseEvent {
|
|
9
|
-
ts: number;
|
|
10
|
-
op: string;
|
|
11
|
-
kind: ProfilingEventKind;
|
|
12
|
-
profileId: string;
|
|
13
|
-
}
|
|
14
|
-
export declare function recordPhase(base: BaseEvent, phase: string, ms?: number, extra?: {
|
|
15
|
-
count?: number;
|
|
16
|
-
}): void;
|
|
17
|
-
export declare function recordFailure(base: BaseEvent, startTime: number, error: unknown): void;
|
|
18
|
-
export declare function recordServerBreakdownPhases(base: BaseEvent, server: ServerBreakdown, prefix?: string): void;
|
|
19
|
-
export declare function recordDelegationBreakdownPhases(base: BaseEvent, delegation: DelegationBreakdown, prefix?: string): void;
|
|
20
|
-
//# sourceMappingURL=events.d.ts.map
|
package/dist/profiling/events.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { nowMs } from "./clock.js";
|
|
2
|
-
import { record } from "./controller.js";
|
|
3
|
-
export function recordPhase(base, phase, ms, extra) {
|
|
4
|
-
if (ms === undefined)
|
|
5
|
-
return;
|
|
6
|
-
record({ ...base, phase, ms, ...extra });
|
|
7
|
-
}
|
|
8
|
-
export function recordFailure(base, startTime, error) {
|
|
9
|
-
const now = nowMs();
|
|
10
|
-
record({
|
|
11
|
-
...base,
|
|
12
|
-
ts: now,
|
|
13
|
-
phase: "failed",
|
|
14
|
-
ms: now - startTime,
|
|
15
|
-
tags: {
|
|
16
|
-
error: error instanceof Error ? error.name : "Unknown",
|
|
17
|
-
message: error instanceof Error
|
|
18
|
-
? error.message.slice(0, 100)
|
|
19
|
-
: String(error).slice(0, 100),
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
export function recordServerBreakdownPhases(base, server, prefix = "server") {
|
|
24
|
-
recordPhase(base, `${prefix}.request.jsonParse`, server.requestJsonParseMs);
|
|
25
|
-
recordPhase(base, `${prefix}.request.zodValidation`, server.requestZodValidationMs);
|
|
26
|
-
recordPhase(base, `${prefix}.handlerExecution`, server.handlerExecutionMs);
|
|
27
|
-
recordPhase(base, `${prefix}.response.zodValidation`, server.responseZodValidationMs);
|
|
28
|
-
recordPhase(base, `${prefix}.response.stringify`, server.responseStringifyMs);
|
|
29
|
-
recordPhase(base, `${prefix}.totalServerTime`, server.totalServerMs);
|
|
30
|
-
}
|
|
31
|
-
export function recordDelegationBreakdownPhases(base, delegation, prefix = "delegation") {
|
|
32
|
-
recordPhase(base, `${prefix}.connection`, delegation.connectionMs);
|
|
33
|
-
recordPhase(base, `${prefix}.request.stringify`, delegation.requestStringifyMs);
|
|
34
|
-
recordPhase(base, `${prefix}.serverWait`, delegation.serverWaitMs);
|
|
35
|
-
recordPhase(base, `${prefix}.response.jsonParse`, delegation.responseJsonParseMs);
|
|
36
|
-
recordPhase(base, `${prefix}.totalDelegationTime`, delegation.totalDelegationMs);
|
|
37
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JSON, table, and summary export utilities for profiling data.
|
|
3
|
-
*/
|
|
4
|
-
import type { ProfilerExport } from "./types";
|
|
5
|
-
export declare function exportJSON(options?: {
|
|
6
|
-
includeRecentEvents?: boolean;
|
|
7
|
-
}): ProfilerExport;
|
|
8
|
-
export declare function exportTable(): string;
|
|
9
|
-
export declare function exportSummary(): string;
|
|
10
|
-
//# sourceMappingURL=exporters.d.ts.map
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JSON, table, and summary export utilities for profiling data.
|
|
3
|
-
*/
|
|
4
|
-
import { getEffectiveConfig, getAggregates, getRecentEvents, } from "./controller.js";
|
|
5
|
-
import { getDroppedCount, getEventCount } from "./aggregator.js";
|
|
6
|
-
import { nowMs, getClockSource, isMonotonic } from "./clock.js";
|
|
7
|
-
export function exportJSON(options) {
|
|
8
|
-
const config = getEffectiveConfig();
|
|
9
|
-
const includeRecent = options?.includeRecentEvents ?? true;
|
|
10
|
-
const result = {
|
|
11
|
-
config,
|
|
12
|
-
aggregates: getAggregates(),
|
|
13
|
-
exportedAt: nowMs(),
|
|
14
|
-
};
|
|
15
|
-
if (includeRecent && config.mode === "verbose") {
|
|
16
|
-
result.recentEvents = getRecentEvents();
|
|
17
|
-
}
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
function aggregateMatchingStats(aggregates, predicate) {
|
|
21
|
-
const matches = Object.entries(aggregates).filter(([key]) => predicate(key));
|
|
22
|
-
if (matches.length === 0) {
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
let count = 0;
|
|
26
|
-
let sum = 0;
|
|
27
|
-
let min = Infinity;
|
|
28
|
-
let max = -Infinity;
|
|
29
|
-
let last = 0;
|
|
30
|
-
for (const [, stats] of matches) {
|
|
31
|
-
count += stats.count;
|
|
32
|
-
sum += stats.sum;
|
|
33
|
-
if (stats.count > 0) {
|
|
34
|
-
if (stats.min < min)
|
|
35
|
-
min = stats.min;
|
|
36
|
-
if (stats.max > max)
|
|
37
|
-
max = stats.max;
|
|
38
|
-
last = stats.last;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
count,
|
|
43
|
-
min: count > 0 ? min : 0,
|
|
44
|
-
max: count > 0 ? max : 0,
|
|
45
|
-
avg: count > 0 ? sum / count : 0,
|
|
46
|
-
sum,
|
|
47
|
-
last,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
function formatDuration(ms) {
|
|
51
|
-
if (ms < 1) {
|
|
52
|
-
return `${(ms * 1000).toFixed(0)}μs`;
|
|
53
|
-
}
|
|
54
|
-
if (ms < 1000) {
|
|
55
|
-
return `${ms.toFixed(1)}ms`;
|
|
56
|
-
}
|
|
57
|
-
if (ms < 60000) {
|
|
58
|
-
return `${(ms / 1000).toFixed(2)}s`;
|
|
59
|
-
}
|
|
60
|
-
return `${(ms / 60000).toFixed(2)}m`;
|
|
61
|
-
}
|
|
62
|
-
function formatBytes(bytes) {
|
|
63
|
-
if (bytes < 1024)
|
|
64
|
-
return `${bytes.toFixed(0)} B`;
|
|
65
|
-
if (bytes < 1024 * 1024)
|
|
66
|
-
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
67
|
-
if (bytes < 1024 * 1024 * 1024)
|
|
68
|
-
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
|
|
69
|
-
return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
|
70
|
-
}
|
|
71
|
-
function formatThroughput(bps) {
|
|
72
|
-
if (bps < 1024)
|
|
73
|
-
return `${bps.toFixed(0)} B/s`;
|
|
74
|
-
if (bps < 1024 * 1024)
|
|
75
|
-
return `${(bps / 1024).toFixed(1)} KB/s`;
|
|
76
|
-
if (bps < 1024 * 1024 * 1024)
|
|
77
|
-
return `${(bps / (1024 * 1024)).toFixed(2)} MB/s`;
|
|
78
|
-
return `${(bps / (1024 * 1024 * 1024)).toFixed(2)} GB/s`;
|
|
79
|
-
}
|
|
80
|
-
function formatNumber(n) {
|
|
81
|
-
if (Number.isInteger(n)) {
|
|
82
|
-
return n.toLocaleString();
|
|
83
|
-
}
|
|
84
|
-
if (n === 0)
|
|
85
|
-
return "0";
|
|
86
|
-
if (Math.abs(n) < 0.01)
|
|
87
|
-
return n.toExponential(2);
|
|
88
|
-
if (Math.abs(n) < 1)
|
|
89
|
-
return n.toFixed(3);
|
|
90
|
-
if (Math.abs(n) < 100)
|
|
91
|
-
return n.toFixed(2);
|
|
92
|
-
return n.toFixed(1);
|
|
93
|
-
}
|
|
94
|
-
function detectMetricType(metricName) {
|
|
95
|
-
const lowerName = metricName.toLowerCase();
|
|
96
|
-
if (lowerName.includes("bps") || lowerName.includes("speed")) {
|
|
97
|
-
return "throughput";
|
|
98
|
-
}
|
|
99
|
-
if (lowerName.includes("bytes") || lowerName.includes("downloaded") || lowerName.includes("size")) {
|
|
100
|
-
return "bytes";
|
|
101
|
-
}
|
|
102
|
-
if (lowerName.endsWith("time") ||
|
|
103
|
-
lowerName.endsWith("ms") ||
|
|
104
|
-
lowerName.endsWith("duration") ||
|
|
105
|
-
lowerName.includes("ttfb") ||
|
|
106
|
-
lowerName.includes("latency") ||
|
|
107
|
-
lowerName.includes("wait") ||
|
|
108
|
-
lowerName.includes("overhead") ||
|
|
109
|
-
lowerName.includes("parse") ||
|
|
110
|
-
lowerName.includes("stringify") ||
|
|
111
|
-
lowerName.includes("validation") ||
|
|
112
|
-
lowerName.includes("execution") ||
|
|
113
|
-
lowerName.includes("serialization") ||
|
|
114
|
-
lowerName.includes("connection")) {
|
|
115
|
-
return "duration";
|
|
116
|
-
}
|
|
117
|
-
if (lowerName.includes("count") || lowerName.includes("token")) {
|
|
118
|
-
return "number";
|
|
119
|
-
}
|
|
120
|
-
// Default to duration for unknown metrics (most profiling is timing)
|
|
121
|
-
return "duration";
|
|
122
|
-
}
|
|
123
|
-
function formatMetricValue(value, metricName) {
|
|
124
|
-
const type = detectMetricType(metricName);
|
|
125
|
-
switch (type) {
|
|
126
|
-
case "bytes":
|
|
127
|
-
return formatBytes(value);
|
|
128
|
-
case "throughput":
|
|
129
|
-
return formatThroughput(value);
|
|
130
|
-
case "number":
|
|
131
|
-
return formatNumber(value);
|
|
132
|
-
case "duration":
|
|
133
|
-
default:
|
|
134
|
-
return formatDuration(value);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
function pad(s, len, align = "left") {
|
|
138
|
-
if (s.length >= len)
|
|
139
|
-
return s.substring(0, len);
|
|
140
|
-
const spaces = " ".repeat(len - s.length);
|
|
141
|
-
return align === "left" ? s + spaces : spaces + s;
|
|
142
|
-
}
|
|
143
|
-
export function exportTable() {
|
|
144
|
-
const aggregates = getAggregates();
|
|
145
|
-
const entries = Object.entries(aggregates);
|
|
146
|
-
if (entries.length === 0) {
|
|
147
|
-
return "No profiling data recorded.";
|
|
148
|
-
}
|
|
149
|
-
const metricWidth = 40;
|
|
150
|
-
const numWidth = 12;
|
|
151
|
-
const header = [
|
|
152
|
-
pad("Metric", metricWidth),
|
|
153
|
-
pad("Count", numWidth, "right"),
|
|
154
|
-
pad("Min", numWidth, "right"),
|
|
155
|
-
pad("Max", numWidth, "right"),
|
|
156
|
-
pad("Avg", numWidth, "right"),
|
|
157
|
-
pad("Total", numWidth, "right"),
|
|
158
|
-
].join(" | ");
|
|
159
|
-
const separator = "-".repeat(header.length);
|
|
160
|
-
const rows = entries
|
|
161
|
-
.sort((a, b) => a[0].localeCompare(b[0]))
|
|
162
|
-
.map(([metric, stats]) => {
|
|
163
|
-
return [
|
|
164
|
-
pad(metric, metricWidth),
|
|
165
|
-
pad(formatNumber(stats.count), numWidth, "right"),
|
|
166
|
-
pad(formatMetricValue(stats.min, metric), numWidth, "right"),
|
|
167
|
-
pad(formatMetricValue(stats.max, metric), numWidth, "right"),
|
|
168
|
-
pad(formatMetricValue(stats.avg, metric), numWidth, "right"),
|
|
169
|
-
pad(formatMetricValue(stats.sum, metric), numWidth, "right"),
|
|
170
|
-
].join(" | ");
|
|
171
|
-
});
|
|
172
|
-
return [separator, header, separator, ...rows, separator].join("\n");
|
|
173
|
-
}
|
|
174
|
-
export function exportSummary() {
|
|
175
|
-
const aggregates = getAggregates();
|
|
176
|
-
const config = getEffectiveConfig();
|
|
177
|
-
const eventCount = getEventCount();
|
|
178
|
-
const droppedCount = getDroppedCount();
|
|
179
|
-
const lines = [
|
|
180
|
-
"=".repeat(60),
|
|
181
|
-
"PROFILER SUMMARY",
|
|
182
|
-
"=".repeat(60),
|
|
183
|
-
"",
|
|
184
|
-
"Session:",
|
|
185
|
-
` Status: ${config.enabled ? "enabled" : "disabled"}`,
|
|
186
|
-
` Mode: ${config.mode}`,
|
|
187
|
-
` Clock: ${getClockSource()} (monotonic: ${isMonotonic()})`,
|
|
188
|
-
` Events: ${eventCount.toLocaleString()}`,
|
|
189
|
-
` Dropped: ${droppedCount.toLocaleString()}`,
|
|
190
|
-
"",
|
|
191
|
-
];
|
|
192
|
-
const keyMetrics = [
|
|
193
|
-
{
|
|
194
|
-
label: "RPC Total",
|
|
195
|
-
stats: aggregateMatchingStats(aggregates, (key) => key.endsWith(".totalClientTime")),
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
label: "Handler",
|
|
199
|
-
stats: aggregateMatchingStats(aggregates, (key) => key.endsWith(".server.handlerExecution") || !key.includes(".")),
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
label: "Model Load",
|
|
203
|
-
stats: aggregateMatchingStats(aggregates, (key) => key === "load.totalTime" || key.endsWith(".load.totalTime")),
|
|
204
|
-
},
|
|
205
|
-
{
|
|
206
|
-
label: "Download",
|
|
207
|
-
stats: aggregateMatchingStats(aggregates, (key) => key === "download.time" || key.endsWith(".download.time")),
|
|
208
|
-
},
|
|
209
|
-
];
|
|
210
|
-
const hasMetrics = keyMetrics.some((m) => m.stats);
|
|
211
|
-
if (hasMetrics) {
|
|
212
|
-
lines.push("Key Metrics:");
|
|
213
|
-
lines.push("-".repeat(60));
|
|
214
|
-
lines.push(" " +
|
|
215
|
-
"Metric".padEnd(18) +
|
|
216
|
-
"Samples".padStart(10) +
|
|
217
|
-
"Avg".padStart(12) +
|
|
218
|
-
"Total".padStart(12));
|
|
219
|
-
lines.push("-".repeat(60));
|
|
220
|
-
for (const { label, stats } of keyMetrics) {
|
|
221
|
-
if (stats) {
|
|
222
|
-
const name = label.padEnd(18);
|
|
223
|
-
const samples = String(stats.count).padStart(10);
|
|
224
|
-
const avg = formatDuration(stats.avg).padStart(12);
|
|
225
|
-
const total = formatDuration(stats.sum).padStart(12);
|
|
226
|
-
lines.push(` ${name}${samples}${avg}${total}`);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
lines.push("No metrics recorded yet.");
|
|
232
|
-
}
|
|
233
|
-
lines.push("");
|
|
234
|
-
lines.push("=".repeat(60));
|
|
235
|
-
return lines.join("\n");
|
|
236
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* QVAC SDK Profiler
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```ts
|
|
6
|
-
* import { profiler } from "@qvac/sdk";
|
|
7
|
-
*
|
|
8
|
-
* profiler.enable({ mode: "summary" });
|
|
9
|
-
* // ... run SDK operations ...
|
|
10
|
-
* console.log(profiler.exportTable());
|
|
11
|
-
* profiler.disable();
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
import * as controller from "./controller";
|
|
15
|
-
import type { ProfilerRuntimeOptions, ProfilingEvent, ProfilerExport, AggregatedStats } from "./types";
|
|
16
|
-
export declare const profiler: {
|
|
17
|
-
enable: (options?: ProfilerRuntimeOptions) => void;
|
|
18
|
-
disable: () => void;
|
|
19
|
-
isEnabled: () => boolean;
|
|
20
|
-
exportJSON: (options?: {
|
|
21
|
-
includeRecentEvents?: boolean;
|
|
22
|
-
}) => ProfilerExport;
|
|
23
|
-
exportTable: () => string;
|
|
24
|
-
exportSummary: () => string;
|
|
25
|
-
onRecord: (callback: (event: ProfilingEvent) => void) => () => void;
|
|
26
|
-
getConfig: () => controller.ResolvedProfilerConfig;
|
|
27
|
-
getAggregates: () => Record<string, AggregatedStats>;
|
|
28
|
-
clear: () => void;
|
|
29
|
-
};
|
|
30
|
-
export type { ProfilerRuntimeOptions, ProfilingEvent, ProfilerExport, AggregatedStats, ProfilingEventKind, } from "./types";
|
|
31
|
-
export type { ProfilerMode } from "../schemas/index";
|
|
32
|
-
export { nowMs } from "./clock";
|
|
33
|
-
export { record, shouldProfile, shouldIncludeServerBreakdown, generateId, isEnabled, type ResolvedProfilerConfig, } from "./controller";
|
|
34
|
-
export { createProfilingMeta, createProfilingDisabledMeta, injectProfilingMetaIntoObject, extractProfilingMeta, stripProfilingMeta, } from "./envelope";
|
|
35
|
-
export { recordPhase, recordFailure, recordServerBreakdownPhases, recordDelegationBreakdownPhases, type BaseTimings, type BaseEvent, } from "./events";
|
|
36
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/profiling/index.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* QVAC SDK Profiler
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```ts
|
|
6
|
-
* import { profiler } from "@qvac/sdk";
|
|
7
|
-
*
|
|
8
|
-
* profiler.enable({ mode: "summary" });
|
|
9
|
-
* // ... run SDK operations ...
|
|
10
|
-
* console.log(profiler.exportTable());
|
|
11
|
-
* profiler.disable();
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
import * as controller from "./controller.js";
|
|
15
|
-
import * as exporters from "./exporters.js";
|
|
16
|
-
export const profiler = {
|
|
17
|
-
enable: (options) => controller.enable(options),
|
|
18
|
-
disable: () => controller.disable(),
|
|
19
|
-
isEnabled: () => controller.isEnabled(),
|
|
20
|
-
exportJSON: (options) => exporters.exportJSON(options),
|
|
21
|
-
exportTable: () => exporters.exportTable(),
|
|
22
|
-
exportSummary: () => exporters.exportSummary(),
|
|
23
|
-
onRecord: (callback) => controller.onRecord(callback),
|
|
24
|
-
getConfig: () => controller.getEffectiveConfig(),
|
|
25
|
-
getAggregates: () => controller.getAggregates(),
|
|
26
|
-
clear: () => controller.clear(),
|
|
27
|
-
};
|
|
28
|
-
export { nowMs } from "./clock.js";
|
|
29
|
-
export { record, shouldProfile, shouldIncludeServerBreakdown, generateId, isEnabled, } from "./controller.js";
|
|
30
|
-
export { createProfilingMeta, createProfilingDisabledMeta, injectProfilingMetaIntoObject, extractProfilingMeta, stripProfilingMeta, } from "./envelope.js";
|
|
31
|
-
export { recordPhase, recordFailure, recordServerBreakdownPhases, recordDelegationBreakdownPhases, } from "./events.js";
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* O(1) bounded buffer for event storage.
|
|
3
|
-
* Oldest events are overwritten when full.
|
|
4
|
-
*/
|
|
5
|
-
export interface RingBufferState<T> {
|
|
6
|
-
buffer: (T | undefined)[];
|
|
7
|
-
capacity: number;
|
|
8
|
-
head: number;
|
|
9
|
-
size: number;
|
|
10
|
-
totalPushed: number;
|
|
11
|
-
}
|
|
12
|
-
export declare function createRingBuffer<T>(capacity: number): RingBufferState<T>;
|
|
13
|
-
export declare function ringBufferPush<T>(state: RingBufferState<T>, item: T): T | undefined;
|
|
14
|
-
export declare function ringBufferToArray<T>(state: RingBufferState<T>): T[];
|
|
15
|
-
export declare function ringBufferGetRecent<T>(state: RingBufferState<T>, count: number): T[];
|
|
16
|
-
export declare function ringBufferClear<T>(state: RingBufferState<T>): void;
|
|
17
|
-
export declare function ringBufferDroppedCount<T>(state: RingBufferState<T>): number;
|
|
18
|
-
export declare function ringBufferResize<T>(state: RingBufferState<T>, newCapacity: number): RingBufferState<T>;
|
|
19
|
-
//# sourceMappingURL=ring-buffer.d.ts.map
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* O(1) bounded buffer for event storage.
|
|
3
|
-
* Oldest events are overwritten when full.
|
|
4
|
-
*/
|
|
5
|
-
import { ProfilerInvalidCapacityError } from "../utils/errors-client.js";
|
|
6
|
-
export function createRingBuffer(capacity) {
|
|
7
|
-
if (capacity < 1) {
|
|
8
|
-
throw new ProfilerInvalidCapacityError(1);
|
|
9
|
-
}
|
|
10
|
-
return {
|
|
11
|
-
buffer: new Array(capacity),
|
|
12
|
-
capacity,
|
|
13
|
-
head: 0,
|
|
14
|
-
size: 0,
|
|
15
|
-
totalPushed: 0,
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
// Returns the overwritten item if buffer was full, undefined otherwise.
|
|
19
|
-
export function ringBufferPush(state, item) {
|
|
20
|
-
const overwritten = state.size === state.capacity ? state.buffer[state.head] : undefined;
|
|
21
|
-
state.buffer[state.head] = item;
|
|
22
|
-
state.head = (state.head + 1) % state.capacity;
|
|
23
|
-
state.size = Math.min(state.size + 1, state.capacity);
|
|
24
|
-
state.totalPushed++;
|
|
25
|
-
return overwritten;
|
|
26
|
-
}
|
|
27
|
-
// Returns all items in chronological order (oldest first).
|
|
28
|
-
export function ringBufferToArray(state) {
|
|
29
|
-
if (state.size === 0) {
|
|
30
|
-
return [];
|
|
31
|
-
}
|
|
32
|
-
const result = [];
|
|
33
|
-
const start = state.size === state.capacity
|
|
34
|
-
? state.head // Full: head points to oldest
|
|
35
|
-
: 0;
|
|
36
|
-
for (let i = 0; i < state.size; i++) {
|
|
37
|
-
const index = (start + i) % state.capacity;
|
|
38
|
-
const item = state.buffer[index];
|
|
39
|
-
if (item !== undefined) {
|
|
40
|
-
result.push(item);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return result;
|
|
44
|
-
}
|
|
45
|
-
// Returns the most recent N items (newest first).
|
|
46
|
-
export function ringBufferGetRecent(state, count) {
|
|
47
|
-
if (state.size === 0 || count <= 0) {
|
|
48
|
-
return [];
|
|
49
|
-
}
|
|
50
|
-
const actualCount = Math.min(count, state.size);
|
|
51
|
-
const result = [];
|
|
52
|
-
for (let i = 0; i < actualCount; i++) {
|
|
53
|
-
const index = (state.head - 1 - i + state.capacity) % state.capacity;
|
|
54
|
-
const item = state.buffer[index];
|
|
55
|
-
if (item !== undefined) {
|
|
56
|
-
result.push(item);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return result;
|
|
60
|
-
}
|
|
61
|
-
export function ringBufferClear(state) {
|
|
62
|
-
state.buffer = new Array(state.capacity);
|
|
63
|
-
state.head = 0;
|
|
64
|
-
state.size = 0;
|
|
65
|
-
state.totalPushed = 0;
|
|
66
|
-
}
|
|
67
|
-
export function ringBufferDroppedCount(state) {
|
|
68
|
-
return Math.max(0, state.totalPushed - state.capacity);
|
|
69
|
-
}
|
|
70
|
-
// Resizes the buffer, keeping the most recent items.
|
|
71
|
-
export function ringBufferResize(state, newCapacity) {
|
|
72
|
-
if (newCapacity < 1) {
|
|
73
|
-
throw new ProfilerInvalidCapacityError(1);
|
|
74
|
-
}
|
|
75
|
-
const items = ringBufferToArray(state);
|
|
76
|
-
const itemsToKeep = items.slice(-newCapacity);
|
|
77
|
-
const newState = createRingBuffer(newCapacity);
|
|
78
|
-
for (const item of itemsToKeep) {
|
|
79
|
-
ringBufferPush(newState, item);
|
|
80
|
-
}
|
|
81
|
-
newState.totalPushed = state.totalPushed;
|
|
82
|
-
return newState;
|
|
83
|
-
}
|