Conversation
| /** | ||
| * Create a new RealtimeAPI instance | ||
| * @param {{url?: string, apiKey?: string, dangerouslyAllowAPIKeyInBrowser?: boolean, debug?: boolean}} [settings] | ||
| * @returns {RealtimeAPI} |
There was a problem hiding this comment.
I don't think returns should be defined on the constructor
| if (!this.isConnected()) { | ||
| throw new Error(`RealtimeAPI is not connected`); | ||
| } | ||
| data = data || {}; |
| /** | ||
| * @typedef {Object} InputAudioContentType | ||
| * @property {"input_audio"} type | ||
| * @property {string} [audio] base64-encoded audio data |
There was a problem hiding this comment.
later we check if ArrayBuffer | Int16Array, and if so, we convert to base64. Here we ensure the type allows for ArrayBuffer | Int16Array
| this.getTurnDetectionType() === null && | ||
| this.inputAudioBuffer.byteLength > 0 | ||
| ) { | ||
| this.realtime.send('input_audio_buffer.commit'); |
There was a problem hiding this comment.
Didn't find a way yet to skip the second argument if it's nullable
|
|
||
| /** | ||
| * Utility for waiting for the next `conversation.item.appended` event to be triggered by the server | ||
| * @returns {Promise<{item: ItemType}>} |
There was a problem hiding this comment.
The return type is implicit from this.waitForNext method
| @@ -0,0 +1,367 @@ | |||
| import { EventEmitter } from 'events'; | |||
There was a problem hiding this comment.
This file is a draft and needs to be cleaned up
| "include": ["index.js"], | ||
| "compilerOptions": { | ||
| "allowJs": true, | ||
| "checkJs": true, |
There was a problem hiding this comment.
Brings full type-checking for js project
58ca906 to
40f773d
Compare
| * Process an event from the WebSocket server and compose items | ||
| * @param {Object} event | ||
| * @param {...any} args | ||
| * @returns {item: import('./client.js').ItemType | null, delta: ItemContentDeltaType | null} |
There was a problem hiding this comment.
This was a jsdoc error I think - we need double braces to define object
|
I did not check in the dist change, just to keep the draft PR clean. But this branch passes |
This is an experimental approach to get full types to events, both when sending them and receiving them. I import typescript types with jsdoc require from a types.ts file. There might be some benefit to move the original jsdoc definitions to the types.ts files, making them more flexible and easier to read.
When sending events, the typing of the object depends on the name of the event we are sending:

And same when receiving event, the type of the returned object is based on the eventName (first argument)
