@@ -59,7 +59,7 @@ import { RealtimeUtils } from './utils.js';
5959/**
6060 * @typedef {Object } InputAudioContentType
6161 * @property {"input_audio" } type
62- * @property {string } [audio] base64-encoded audio data
62+ * @property {string|ArrayBuffer|Int16Array } [audio] base64-encoded audio data
6363 * @property {string|null } [transcript]
6464 */
6565
@@ -193,6 +193,7 @@ export class RealtimeClient extends RealtimeEventHandler {
193193 */
194194 constructor ( { url, apiKey, dangerouslyAllowAPIKeyInBrowser, debug } = { } ) {
195195 super ( ) ;
196+ /* @type { import('./types').SessionConfig }*/
196197 this . defaultSessionConfig = {
197198 modalities : [ 'text' , 'audio' ] ,
198199 instructions : '' ,
@@ -295,6 +296,7 @@ export class RealtimeClient extends RealtimeEventHandler {
295296 throw new Error ( `Tool "${ tool . name } " has not been added` ) ;
296297 }
297298 const result = await toolConfig . handler ( jsonArguments ) ;
299+
298300 this . realtime . send ( 'conversation.item.create' , {
299301 item : {
300302 type : 'function_call_output' ,
@@ -344,6 +346,7 @@ export class RealtimeClient extends RealtimeEventHandler {
344346 'server.response.audio_transcript.delta' ,
345347 handlerWithDispatch ,
346348 ) ;
349+
347350 this . realtime . on ( 'server.response.audio.delta' , handlerWithDispatch ) ;
348351 this . realtime . on ( 'server.response.text.delta' , handlerWithDispatch ) ;
349352 this . realtime . on (
@@ -533,7 +536,7 @@ export class RealtimeClient extends RealtimeEventHandler {
533536 } ;
534537 } ) ,
535538 ) ;
536- const session = { ...this . sessionConfig } ;
539+ const session = { ...this . sessionConfig , tools : useTools } ;
537540 session . tools = useTools ;
538541 if ( this . realtime . isConnected ( ) ) {
539542 this . realtime . send ( 'session.update' , { session } ) ;
@@ -559,6 +562,7 @@ export class RealtimeClient extends RealtimeEventHandler {
559562 item : {
560563 type : 'message' ,
561564 role : 'user' ,
565+ //@ts -ignore TODO fix
562566 content,
563567 } ,
564568 } ) ;
@@ -594,11 +598,11 @@ export class RealtimeClient extends RealtimeEventHandler {
594598 this . getTurnDetectionType ( ) === null &&
595599 this . inputAudioBuffer . byteLength > 0
596600 ) {
597- this . realtime . send ( 'input_audio_buffer.commit' ) ;
601+ this . realtime . send ( 'input_audio_buffer.commit' , null ) ;
598602 this . conversation . queueInputAudio ( this . inputAudioBuffer ) ;
599603 this . inputAudioBuffer = new Int16Array ( 0 ) ;
600604 }
601- this . realtime . send ( 'response.create' ) ;
605+ this . realtime . send ( 'response.create' , null ) ;
602606 return true ;
603607 }
604608
@@ -611,7 +615,7 @@ export class RealtimeClient extends RealtimeEventHandler {
611615 */
612616 cancelResponse ( id , sampleCount = 0 ) {
613617 if ( ! id ) {
614- this . realtime . send ( 'response.cancel' ) ;
618+ this . realtime . send ( 'response.cancel' , null ) ;
615619 return { item : null } ;
616620 } else if ( id ) {
617621 const item = this . conversation . getItem ( id ) ;
@@ -625,7 +629,7 @@ export class RealtimeClient extends RealtimeEventHandler {
625629 `Can only cancelResponse messages with role "assistant"` ,
626630 ) ;
627631 }
628- this . realtime . send ( 'response.cancel' ) ;
632+ this . realtime . send ( 'response.cancel' , null ) ;
629633 const audioIndex = item . content . findIndex ( ( c ) => c . type === 'audio' ) ;
630634 if ( audioIndex === - 1 ) {
631635 throw new Error ( `Could not find audio on item to cancel` ) ;
@@ -643,7 +647,6 @@ export class RealtimeClient extends RealtimeEventHandler {
643647
644648 /**
645649 * Utility for waiting for the next `conversation.item.appended` event to be triggered by the server
646- * @returns {Promise<{item: ItemType}> }
647650 */
648651 async waitForNextItem ( ) {
649652 const event = await this . waitForNext ( 'conversation.item.appended' ) ;
@@ -653,7 +656,6 @@ export class RealtimeClient extends RealtimeEventHandler {
653656
654657 /**
655658 * Utility for waiting for the next `conversation.item.completed` event to be triggered by the server
656- * @returns {Promise<{item: ItemType}> }
657659 */
658660 async waitForNextCompletedItem ( ) {
659661 const event = await this . waitForNext ( 'conversation.item.completed' ) ;
0 commit comments