@@ -59,7 +59,7 @@ import { RealtimeUtils } from './utils.js';
59
59
/**
60
60
* @typedef {Object } InputAudioContentType
61
61
* @property {"input_audio" } type
62
- * @property {string } [audio] base64-encoded audio data
62
+ * @property {string|ArrayBuffer|Int16Array } [audio] base64-encoded audio data
63
63
* @property {string|null } [transcript]
64
64
*/
65
65
@@ -193,6 +193,7 @@ export class RealtimeClient extends RealtimeEventHandler {
193
193
*/
194
194
constructor ( { url, apiKey, dangerouslyAllowAPIKeyInBrowser, debug } = { } ) {
195
195
super ( ) ;
196
+ /* @type { import('./types').SessionConfig }*/
196
197
this . defaultSessionConfig = {
197
198
modalities : [ 'text' , 'audio' ] ,
198
199
instructions : '' ,
@@ -295,6 +296,7 @@ export class RealtimeClient extends RealtimeEventHandler {
295
296
throw new Error ( `Tool "${ tool . name } " has not been added` ) ;
296
297
}
297
298
const result = await toolConfig . handler ( jsonArguments ) ;
299
+
298
300
this . realtime . send ( 'conversation.item.create' , {
299
301
item : {
300
302
type : 'function_call_output' ,
@@ -344,6 +346,7 @@ export class RealtimeClient extends RealtimeEventHandler {
344
346
'server.response.audio_transcript.delta' ,
345
347
handlerWithDispatch ,
346
348
) ;
349
+
347
350
this . realtime . on ( 'server.response.audio.delta' , handlerWithDispatch ) ;
348
351
this . realtime . on ( 'server.response.text.delta' , handlerWithDispatch ) ;
349
352
this . realtime . on (
@@ -533,7 +536,7 @@ export class RealtimeClient extends RealtimeEventHandler {
533
536
} ;
534
537
} ) ,
535
538
) ;
536
- const session = { ...this . sessionConfig } ;
539
+ const session = { ...this . sessionConfig , tools : useTools } ;
537
540
session . tools = useTools ;
538
541
if ( this . realtime . isConnected ( ) ) {
539
542
this . realtime . send ( 'session.update' , { session } ) ;
@@ -559,6 +562,7 @@ export class RealtimeClient extends RealtimeEventHandler {
559
562
item : {
560
563
type : 'message' ,
561
564
role : 'user' ,
565
+ //@ts -ignore TODO fix
562
566
content,
563
567
} ,
564
568
} ) ;
@@ -594,11 +598,11 @@ export class RealtimeClient extends RealtimeEventHandler {
594
598
this . getTurnDetectionType ( ) === null &&
595
599
this . inputAudioBuffer . byteLength > 0
596
600
) {
597
- this . realtime . send ( 'input_audio_buffer.commit' ) ;
601
+ this . realtime . send ( 'input_audio_buffer.commit' , null ) ;
598
602
this . conversation . queueInputAudio ( this . inputAudioBuffer ) ;
599
603
this . inputAudioBuffer = new Int16Array ( 0 ) ;
600
604
}
601
- this . realtime . send ( 'response.create' ) ;
605
+ this . realtime . send ( 'response.create' , null ) ;
602
606
return true ;
603
607
}
604
608
@@ -611,7 +615,7 @@ export class RealtimeClient extends RealtimeEventHandler {
611
615
*/
612
616
cancelResponse ( id , sampleCount = 0 ) {
613
617
if ( ! id ) {
614
- this . realtime . send ( 'response.cancel' ) ;
618
+ this . realtime . send ( 'response.cancel' , null ) ;
615
619
return { item : null } ;
616
620
} else if ( id ) {
617
621
const item = this . conversation . getItem ( id ) ;
@@ -625,7 +629,7 @@ export class RealtimeClient extends RealtimeEventHandler {
625
629
`Can only cancelResponse messages with role "assistant"` ,
626
630
) ;
627
631
}
628
- this . realtime . send ( 'response.cancel' ) ;
632
+ this . realtime . send ( 'response.cancel' , null ) ;
629
633
const audioIndex = item . content . findIndex ( ( c ) => c . type === 'audio' ) ;
630
634
if ( audioIndex === - 1 ) {
631
635
throw new Error ( `Could not find audio on item to cancel` ) ;
@@ -643,7 +647,6 @@ export class RealtimeClient extends RealtimeEventHandler {
643
647
644
648
/**
645
649
* Utility for waiting for the next `conversation.item.appended` event to be triggered by the server
646
- * @returns {Promise<{item: ItemType}> }
647
650
*/
648
651
async waitForNextItem ( ) {
649
652
const event = await this . waitForNext ( 'conversation.item.appended' ) ;
@@ -653,7 +656,6 @@ export class RealtimeClient extends RealtimeEventHandler {
653
656
654
657
/**
655
658
* Utility for waiting for the next `conversation.item.completed` event to be triggered by the server
656
- * @returns {Promise<{item: ItemType}> }
657
659
*/
658
660
async waitForNextCompletedItem ( ) {
659
661
const event = await this . waitForNext ( 'conversation.item.completed' ) ;
0 commit comments