Skip to content

Commit 4b33779

Browse files
sakirrSiddhesh2377
authored andcommitted
refactor(web-sdk): switch LlamaCppProvider and ONNXProvider to use ExtensionPoint
Both providers now call ExtensionPoint.registerProvider instead of writing to globalThis. Removes the implicit string contract between packages — the capability keys are now typed enum values checked at compile time.
1 parent 458001b commit 4b33779

2 files changed

Lines changed: 10 additions & 17 deletions

File tree

sdk/runanywhere-web/packages/llamacpp/src/LlamaCppProvider.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
ExtensionPoint,
1616
BackendCapability,
1717
ExtensionRegistry,
18-
ServiceKey,
1918
} from '@runanywhere/web';
2019

2120
import { LlamaCppBridge } from './Foundation/LlamaCppBridge';
@@ -44,14 +43,12 @@ const llamacppExtension: BackendExtension = {
4443
BackendCapability.Diffusion,
4544
],
4645
cleanup() {
47-
// Cleanup all extension singletons
4846
TextGeneration.cleanup();
4947
VLM.cleanup();
5048
ToolCalling.cleanup();
5149
Embeddings.cleanup();
5250
Diffusion.cleanup();
53-
// Remove service registrations
54-
ExtensionPoint.removeService(ServiceKey.TextGeneration);
51+
ExtensionPoint.removeProvider('llm');
5552
_isRegistered = false;
5653
logger.info('LlamaCpp backend cleaned up');
5754
},
@@ -99,9 +96,9 @@ export const LlamaCppProvider = {
9996
// Register with ExtensionPoint for capability lookups
10097
ExtensionPoint.registerBackend(llamacppExtension);
10198

102-
// Register service singletons with ExtensionPoint so VoicePipeline
103-
// (in core) can access them via typed keys at runtime.
104-
ExtensionPoint.registerService(ServiceKey.TextGeneration, TextGeneration);
99+
// Register typed provider so VoicePipeline (in core) can access
100+
// the LLM via ExtensionPoint.getProvider('llm') at runtime.
101+
ExtensionPoint.registerProvider('llm', TextGeneration);
105102

106103
_isRegistered = true;
107104
logger.info('LlamaCpp backend registered successfully');

sdk/runanywhere-web/packages/onnx/src/ONNXProvider.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
ExtensionPoint,
1717
BackendCapability,
1818
ExtensionRegistry,
19-
ServiceKey,
2019
extractTarGz,
2120
} from '@runanywhere/web';
2221

@@ -369,10 +368,8 @@ const onnxExtension: BackendExtension = {
369368
STT.cleanup();
370369
TTS.cleanup();
371370
VAD.cleanup();
372-
// Remove service registrations
373-
ExtensionPoint.removeService(ServiceKey.STT);
374-
ExtensionPoint.removeService(ServiceKey.TTS);
375-
ExtensionPoint.removeService(ServiceKey.VAD);
371+
ExtensionPoint.removeProvider('stt');
372+
ExtensionPoint.removeProvider('tts');
376373
try { SherpaONNXBridge.shared.shutdown(); } catch { /* ignore */ }
377374
_isRegistered = false;
378375
logger.info('ONNX backend cleaned up');
@@ -414,11 +411,10 @@ export const ONNXProvider = {
414411
// Register with ExtensionPoint
415412
ExtensionPoint.registerBackend(onnxExtension);
416413

417-
// Register service singletons with ExtensionPoint so VoicePipeline
418-
// (in core) can access them via typed keys at runtime.
419-
ExtensionPoint.registerService(ServiceKey.STT, STT);
420-
ExtensionPoint.registerService(ServiceKey.TTS, TTS);
421-
ExtensionPoint.registerService(ServiceKey.VAD, VAD);
414+
// Register typed providers so VoicePipeline (in core) can access
415+
// STT/TTS via ExtensionPoint.getProvider() at runtime.
416+
ExtensionPoint.registerProvider('stt', STT);
417+
ExtensionPoint.registerProvider('tts', TTS);
422418

423419
_isRegistered = true;
424420
logger.info('ONNX backend registered successfully');

0 commit comments

Comments
 (0)