support ultravox sends createCall response to app (#1091)

* support ultravox sends createCall response to app

* update type issue

Co-authored-by: Matt Hertogs <matthertogs@gmail.com>

---------

Co-authored-by: Matt Hertogs <matthertogs@gmail.com>
This commit is contained in:
Hoan Luu Huu
2025-02-20 19:07:03 +07:00
committed by GitHub
parent e09c763d3a
commit 4bf2f42f33

View File

@@ -4,6 +4,7 @@ const {request} = require('undici');
const {LlmEvents_Ultravox} = require('../../../utils/constants');
const ultravox_server_events = [
'createCall',
'pong',
'state',
'transcript',
@@ -88,7 +89,7 @@ class TaskLlmUltravox_S2S extends Task {
throw new Error(`Ultravox Error registering call: ${data.message}`);
}
this.logger.info({joinUrl: data.joinUrl}, 'Ultravox Call registered');
return data.joinUrl;
return data;
}
_unregisterHandlers() {
@@ -105,13 +106,19 @@ class TaskLlmUltravox_S2S extends Task {
async _startListening(cs, ep) {
this._registerHandlers(ep);
const joinUrl = await this.createCall();
const data = await this.createCall();
const {joinUrl} = data;
// split the joinUrl into host and path
const {host, pathname, search} = new URL(joinUrl);
try {
const args = [ep.uuid, 'session.create', host, pathname + search];
await this._api(ep, args);
// Notify the application that the session has been created with detail information
this._sendLlmEvent('createCall', {
type: 'createCall',
...data
});
} catch (err) {
this.logger.error({err}, 'TaskLlmUltraVox_S2S:_startListening');
this.notifyTaskDone();
@@ -190,11 +197,7 @@ class TaskLlmUltravox_S2S extends Task {
}
}
/* check whether we should notify on this event */
if (this.includeEvents.length > 0 ? this.includeEvents.includes(type) : !this.excludeEvents.includes(type)) {
this.parent.sendEventHook(evt)
.catch((err) => this.logger.info({err}, 'TaskLlmUltravox_S2S:_onServerEvent - error sending event hook'));
}
this._sendLlmEvent(type, evt);
if (endConversation) {
this.logger.info({results: this.results},
@@ -203,6 +206,14 @@ class TaskLlmUltravox_S2S extends Task {
}
}
_sendLlmEvent(type, evt) {
/* check whether we should notify on this event */
if (this.includeEvents.length > 0 ? this.includeEvents.includes(type) : !this.excludeEvents.includes(type)) {
this.parent.sendEventHook(evt)
.catch((err) => this.logger.info({err}, 'TaskLlmUltravox_S2S:_onServerEvent - error sending event hook'));
}
}
async processToolOutput(ep, tool_call_id, data) {
try {
this.logger.debug({tool_call_id, data}, 'TaskLlmUltravox_S2S:processToolOutput');