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:
parent
8953e9891c
commit
ba0d0b10c4
@ -238,13 +238,14 @@ export class AiAssistantService {
|
|||||||
|
|
||||||
protected async stopCaptionsAssistantIfRunning(roomId: string): Promise<void> {
|
protected async stopCaptionsAssistantIfRunning(roomId: string): Promise<void> {
|
||||||
const assistants = await this.livekitService.listAgents(roomId);
|
const assistants = await this.livekitService.listAgents(roomId);
|
||||||
|
|
||||||
|
if (assistants.length === 0) return;
|
||||||
|
|
||||||
const captionsAssistant = assistants.find(
|
const captionsAssistant = assistants.find(
|
||||||
(assistant) => assistant.agentName === INTERNAL_CONFIG.CAPTIONS_AGENT_NAME
|
(assistant) => assistant.agentName === INTERNAL_CONFIG.CAPTIONS_AGENT_NAME
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!captionsAssistant) {
|
if (!captionsAssistant) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.livekitService.stopAgent(captionsAssistant.id, roomId);
|
await this.livekitService.stopAgent(captionsAssistant.id, roomId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -305,7 +305,7 @@ export class LiveKitService {
|
|||||||
return await this.agentClient.listDispatch(roomName);
|
return await this.agentClient.listDispatch(roomName);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(`Error listing agents for room '${roomName}':`, 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);
|
return await this.agentClient.getDispatch(agentId, roomName);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(`Error getting agent dispatch '${agentId}' for room '${roomName}':`, 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);
|
await this.agentClient.deleteDispatch(agentId, roomName);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(`Error deleting agent dispatch '${agentId}' for room '${roomName}':`, error);
|
this.logger.error(`Error deleting agent dispatch '${agentId}' for room '${roomName}':`, error);
|
||||||
throw internalError(`deleting agent dispatch '${agentId}' for room '${roomName}'`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user