@@ -5,10 +5,7 @@ import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
55import { afterEach , describe , expect , it , vi } from "vitest" ;
66import type WebSocket from "ws" ;
77import { WebSocketServer } from "ws" ;
8- import {
9- testing ,
10- buildDeepgramRealtimeTranscriptionProvider ,
11- } from "./realtime-transcription-provider.js" ;
8+ import { buildDeepgramRealtimeTranscriptionProvider } from "./realtime-transcription-provider.js" ;
129
1310let cleanup : ( ( ) => Promise < void > ) | undefined ;
1411
@@ -45,21 +42,6 @@ async function createDeepgramRealtimeServer(params: {
4542 return { baseUrl : `http://127.0.0.1:${ port } /deepgram/v1` } ;
4643}
4744
48- function buildTestRealtimeUrl ( baseUrl : string ) : URL {
49- return new URL (
50- testing . toDeepgramRealtimeWsUrl ( {
51- apiKey : "dg-key" ,
52- baseUrl,
53- model : "nova-3" ,
54- providerConfig : { } ,
55- sampleRate : 8000 ,
56- encoding : "mulaw" ,
57- interimResults : true ,
58- endpointingMs : 800 ,
59- } ) ,
60- ) ;
61- }
62-
6345describe ( "buildDeepgramRealtimeTranscriptionProvider" , ( ) => {
6446 afterEach ( async ( ) => {
6547 await cleanup ?.( ) ;
@@ -98,24 +80,6 @@ describe("buildDeepgramRealtimeTranscriptionProvider", () => {
9880 } ) ;
9981 } ) ;
10082
101- it ( "builds a Deepgram listen websocket URL" , ( ) => {
102- const url = testing . toDeepgramRealtimeWsUrl ( {
103- apiKey : "dg-key" ,
104- baseUrl : "https://api.deepgram.com/v1" ,
105- model : "nova-3" ,
106- providerConfig : { } ,
107- sampleRate : 8000 ,
108- encoding : "mulaw" ,
109- interimResults : true ,
110- endpointingMs : 800 ,
111- } ) ;
112-
113- expect ( url ) . toContain ( "wss://api.deepgram.com/v1/listen?" ) ;
114- expect ( url ) . toContain ( "model=nova-3" ) ;
115- expect ( url ) . toContain ( "encoding=mulaw" ) ;
116- expect ( url ) . toContain ( "sample_rate=8000" ) ;
117- } ) ;
118-
11983 it ( "requires an API key when creating sessions" , ( ) => {
12084 vi . stubEnv ( "DEEPGRAM_API_KEY" , "" ) ;
12185 const provider = buildDeepgramRealtimeTranscriptionProvider ( ) ;
@@ -124,41 +88,27 @@ describe("buildDeepgramRealtimeTranscriptionProvider", () => {
12488 ) ;
12589 } ) ;
12690
127- it ( "returns the default when no value or env is set" , ( ) => {
128- vi . stubEnv ( "DEEPGRAM_BASE_URL" , "" ) ;
129- expect ( testing . normalizeDeepgramRealtimeBaseUrl ( undefined ) ) . toBe ( "https://api.deepgram.com/v1" ) ;
130- expect ( testing . normalizeDeepgramRealtimeBaseUrl ( " " ) ) . toBe ( "https://api.deepgram.com/v1" ) ;
131- } ) ;
132-
133- it . each ( [
134- [ "http://localhost:8080/deepgram/v1" , "ws:" ] ,
135- [ "https://custom.example.com/deepgram/v1" , "wss:" ] ,
136- [ "ws://localhost:8080/deepgram/v1" , "ws:" ] ,
137- [ "wss://custom.example.com:8443/deepgram/v1" , "wss:" ] ,
138- ] ) ( "maps or preserves %s as %s" , ( baseUrl , expectedProtocol ) => {
139- const url = buildTestRealtimeUrl ( baseUrl ) ;
140- expect ( url . protocol ) . toBe ( expectedProtocol ) ;
141- expect ( url . pathname ) . toBe ( "/deepgram/v1/listen" ) ;
142- } ) ;
143-
14491 it . each ( [ "not a url" , "ftp://files.example.com" ] ) ( "rejects invalid endpoint %s" , ( baseUrl ) => {
145- expect ( ( ) => testing . normalizeDeepgramRealtimeBaseUrl ( baseUrl ) ) . toThrow (
92+ const provider = buildDeepgramRealtimeTranscriptionProvider ( ) ;
93+ expect ( ( ) => provider . createSession ( { providerConfig : { apiKey : "dg-key" , baseUrl } } ) ) . toThrow (
14694 / ^ I n v a l i d D e e p g r a m b a s e U r l : / ,
14795 ) ;
14896 } ) ;
14997
15098 it ( "validates the environment override" , ( ) => {
15199 vi . stubEnv ( "DEEPGRAM_BASE_URL" , "not a url" ) ;
152- expect ( ( ) => testing . normalizeDeepgramRealtimeBaseUrl ( ) ) . toThrow (
100+ const provider = buildDeepgramRealtimeTranscriptionProvider ( ) ;
101+ expect ( ( ) => provider . createSession ( { providerConfig : { apiKey : "dg-key" } } ) ) . toThrow (
153102 "Invalid Deepgram baseUrl: value is not a valid URL" ,
154103 ) ;
155104 } ) ;
156105
157106 it ( "does not echo the configured URL in validation errors" , ( ) => {
158107 const rawMarker = "configured-value-marker" ;
159108 const nonHttp = `ftp://files.example.com/${ rawMarker } ` ;
109+ const provider = buildDeepgramRealtimeTranscriptionProvider ( ) ;
160110 try {
161- testing . normalizeDeepgramRealtimeBaseUrl ( nonHttp ) ;
111+ provider . createSession ( { providerConfig : { apiKey : "dg-key" , baseUrl : nonHttp } } ) ;
162112 throw new Error ( "expected rejection" ) ;
163113 } catch ( error ) {
164114 const message = ( error as Error ) . message ;
0 commit comments