@@ -28,39 +28,21 @@ type SessionSettingsOnConnect = Omit<
2828 Hume . empathicVoice . SessionSettings ,
2929 'builtinTools' | 'tools' | 'metadata' | 'type'
3030> ;
31- type SessionSettingsPostConnect = Pick <
32- Hume . empathicVoice . SessionSettings ,
33- 'builtinTools' | 'tools' | 'metadata' | 'type' | 'systemPrompt'
34- > ;
3531/**
36- * Some session settings can be sent as query params when the websocket connects.
37- * This is preferred because it eliminates a race condition of the session settings being applied slightly after the conversation starts.
38- *
39- * `tools`, `builtinTools`, and `systemPrompt` are not yet supported in the query string. We can remove
40- * this and send everything in the query string once this changes. For the time being
41- * we send as many settings as possible in the query string, and then a complete session
42- * settings message shortly after.
32+ * Extracts session settings that can be sent as query params when the websocket connects.
4333 *
34+ * `tools`, `builtinTools`, `systemPrompt`, and `metadata` are not yet supported in the query string.
4435 */
4536const getSessionSettingsOnConnect = (
4637 sessionSettings ?: Hume . empathicVoice . SessionSettings ,
47- ) : {
48- onConnect ?: SessionSettingsOnConnect ;
49- postConnect ?: SessionSettingsPostConnect ;
50- } => {
38+ ) : SessionSettingsOnConnect | undefined => {
5139 if ( ! sessionSettings ) {
52- return { } ;
40+ return undefined ;
5341 }
5442
5543 const { builtinTools, tools, metadata, type, systemPrompt, ...onConnect } =
5644 sessionSettings ;
57- if ( builtinTools || tools || metadata || systemPrompt ) {
58- return {
59- onConnect,
60- postConnect : sessionSettings ,
61- } ;
62- }
63- return { onConnect } ;
45+ return onConnect ;
6446} ;
6547
6648export type ToolCallHandler = (
@@ -150,8 +132,7 @@ export const useVoiceClient = (props: {
150132 const signal = controller . signal ;
151133 connectAbortController . current = controller ;
152134
153- const { onConnect : connectSettings , postConnect : postConnectSettings } =
154- getSessionSettingsOnConnect ( sessionSettings ) ;
135+ const connectSettings = getSessionSettingsOnConnect ( sessionSettings ) ;
155136
156137 return new Promise < VoiceReadyState > ( ( resolve , reject ) => {
157138 if ( signal . aborted ) {
@@ -205,10 +186,6 @@ export const useVoiceClient = (props: {
205186 onOpen . current ?.( ) ;
206187 setReadyState ( VoiceReadyState . OPEN ) ;
207188 signal . removeEventListener ( 'abort' , abortHandler ) ;
208- if ( postConnectSettings ) {
209- socket . sendSessionSettings ( postConnectSettings ) ;
210- onSessionSettings . current ?.( postConnectSettings ) ;
211- }
212189 resolve ( VoiceReadyState . OPEN ) ;
213190 }
214191
@@ -293,11 +270,7 @@ export const useVoiceClient = (props: {
293270 return ;
294271 }
295272 if ( message . type === 'session_settings' ) {
296- // TODO: we should probably add this to the message store
297- // and stop calling the onSessionSettings with a artificial
298- // session settings message on connect
299- //
300- // onSessionSettings.current?.(message);
273+ onSessionSettings . current ?.( message ) ;
301274 return ;
302275 }
303276
0 commit comments