Skip to content

Commit 7d248d3

Browse files
committed
update
1 parent 4a6f375 commit 7d248d3

File tree

3 files changed

+40
-33
lines changed

3 files changed

+40
-33
lines changed

packages/agents-realtime/src/clientMessages.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export type RealtimeInputAudioTranscriptionConfig = {
4444
};
4545

4646
export type RealtimeTurnDetectionConfigAsIs = {
47-
type?: 'semantic_vad';
47+
type?: 'semantic_vad' | 'server_vad';
4848
create_response?: boolean;
4949
eagerness?: 'auto' | 'low' | 'medium' | 'high';
5050
interrupt_response?: boolean;
@@ -55,7 +55,7 @@ export type RealtimeTurnDetectionConfigAsIs = {
5555

5656
// The Realtime API accepts snake_cased keys, so when using this, this SDK coverts the keys to snake_case ones before passing it to the API
5757
export type RealtimeTurnDetectionConfigCamelCase = {
58-
type?: 'semantic_vad';
58+
type?: 'semantic_vad' | 'server_vad';
5959
createResponse?: boolean;
6060
eagerness?: 'auto' | 'low' | 'medium' | 'high';
6161
interruptResponse?: boolean;
@@ -64,9 +64,11 @@ export type RealtimeTurnDetectionConfigCamelCase = {
6464
threshold?: number;
6565
};
6666

67-
export type RealtimeTurnDetectionConfig =
67+
export type RealtimeTurnDetectionConfig = (
6868
| RealtimeTurnDetectionConfigAsIs
69-
| RealtimeTurnDetectionConfigCamelCase;
69+
| RealtimeTurnDetectionConfigCamelCase
70+
) &
71+
Record<string, any>;
7072

7173
export type RealtimeSessionConfig = {
7274
model: string;

packages/agents-realtime/src/openaiRealtimeBase.ts

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -414,35 +414,40 @@ export abstract class OpenAIRealtimeBase
414414
if (typeof c === 'undefined') {
415415
return undefined;
416416
}
417-
return {
418-
type: c.type,
419-
create_response:
420-
'createResponse' in c
421-
? c.createResponse
422-
: 'create_response' in c
423-
? c.create_response
424-
: undefined,
425-
eagerness: c.eagerness,
426-
interrupt_response:
427-
'interruptResponse' in c
428-
? c.interruptResponse
429-
: 'interrupt_response' in c
430-
? c.interrupt_response
431-
: undefined,
432-
prefix_padding_ms:
433-
'prefixPaddingMs' in c
434-
? c.prefixPaddingMs
435-
: 'prefix_padding_ms' in c
436-
? c.prefix_padding_ms
437-
: undefined,
438-
silence_duration_ms:
439-
'silenceDurationMs' in c
440-
? c.silenceDurationMs
441-
: 'silence_duration_ms' in c
442-
? c.silence_duration_ms
443-
: undefined,
444-
threshold: c.threshold,
417+
const {
418+
type,
419+
createResponse,
420+
create_response,
421+
eagerness,
422+
interruptResponse,
423+
interrupt_response,
424+
prefixPaddingMs,
425+
prefix_padding_ms,
426+
silenceDurationMs,
427+
silence_duration_ms,
428+
threshold,
429+
...rest
430+
} = c;
431+
432+
const config: RealtimeTurnDetectionConfigAsIs & Record<string, any> = {
433+
type,
434+
create_response: createResponse ? createResponse : create_response,
435+
eagerness,
436+
interrupt_response: interruptResponse
437+
? interruptResponse
438+
: interrupt_response,
439+
prefix_padding_ms: prefixPaddingMs ? prefixPaddingMs : prefix_padding_ms,
440+
silence_duration_ms: silenceDurationMs
441+
? silenceDurationMs
442+
: silence_duration_ms,
443+
threshold,
444+
...rest,
445445
};
446+
// Remove undefined values from the config
447+
Object.keys(config).forEach((key) => {
448+
if (config[key] === undefined) delete config[key];
449+
});
450+
return Object.keys(config).length > 0 ? config : undefined;
446451
}
447452

448453
/**

packages/agents-realtime/src/realtimeSession.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ export class RealtimeSession<
519519
this.#transport.on('turn_done', (event) => {
520520
const item = event.response.output[event.response.output.length - 1];
521521
const textOutput = getLastTextFromAudioOutputMessage(item) ?? '';
522-
const itemId = item.id ?? '';
522+
const itemId = item?.id ?? '';
523523
this.emit('agent_end', this.#context, this.#currentAgent, textOutput);
524524
this.#currentAgent.emit('agent_end', this.#context, textOutput);
525525

0 commit comments

Comments
 (0)