backend: Enhances LiveKit agent robustness

LiveKit agent service calls now gracefully handle errors instead of throwing exceptions.

`listAgents` and `getAgent` return sensible defaults (empty array, undefined) on failure, preventing disruption to calling services. `stopAgent` now logs errors during deletion without halting the process.

An early exit condition is also added in the AI assistant service to prevent unnecessary processing if no agents are found, further improving resilience.
This commit is contained in:
CSantosM 2026-03-04 12:33:36 +01:00
parent 8953e9891c
commit ba0d0b10c4
2 changed files with 6 additions and 6 deletions

View File

@ -238,13 +238,14 @@ export class AiAssistantService {
protected async stopCaptionsAssistantIfRunning(roomId: string): Promise<void> {
const assistants = await this.livekitService.listAgents(roomId);
if (assistants.length === 0) return;
const captionsAssistant = assistants.find(
(assistant) => assistant.agentName === INTERNAL_CONFIG.CAPTIONS_AGENT_NAME
);
if (!captionsAssistant) {
return;
}
if (!captionsAssistant) return;
await this.livekitService.stopAgent(captionsAssistant.id, roomId);
}

View File

@ -305,7 +305,7 @@ export class LiveKitService {
return await this.agentClient.listDispatch(roomName);
} catch (error) {
this.logger.error(`Error listing agents for room '${roomName}':`, error);
throw internalError(`listing agents for room '${roomName}'`);
return [];
}
}
@ -320,7 +320,7 @@ export class LiveKitService {
return await this.agentClient.getDispatch(agentId, roomName);
} catch (error) {
this.logger.error(`Error getting agent dispatch '${agentId}' for room '${roomName}':`, error);
throw internalError(`getting agent dispatch '${agentId}' for room '${roomName}'`);
return undefined;
}
}
@ -334,7 +334,6 @@ export class LiveKitService {
await this.agentClient.deleteDispatch(agentId, roomName);
} catch (error) {
this.logger.error(`Error deleting agent dispatch '${agentId}' for room '${roomName}':`, error);
throw internalError(`deleting agent dispatch '${agentId}' for room '${roomName}'`);
}
}