refactor: optimize audio initialization and fix agent interactions

- Lazy initialize audio (on-demand instead of mount) in both player and Speechmatics hooks
- Add audio session teardown on stop for proper cleanup
- Implement agent audio recording with sendAgentAudio in AgentInputArea
- Fix Android navigation race condition in CreateAgentModal (navigate before closing)
- Add animations to global footer and agent screen (FadeIn/FadeOut)
- Auto-cancel stuck agents when sending new messages
- Fix permission request ID propagation from AgentManager to Session
- Apply theme background color via AppContainer wrapper

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Mohamed Boudra
2025-10-23 13:15:18 +02:00
co-authored by Claude
parent 10189514dd
commit 74fffcd8a3
11 changed files with 139 additions and 76 deletions
@@ -268,6 +268,20 @@ export class AgentManager {
throw new Error(`Agent ${agentId} is ${agent.status}`);
}
// Auto-cancel if agent is currently processing
// This allows users to interrupt stuck agents by sending a new message
if (agent.status === "processing") {
console.log(`[Agent ${agentId}] Auto-cancelling current task before new prompt`);
try {
await this.cancelAgent(agentId);
// Small delay to allow cancellation to propagate
await new Promise(resolve => setTimeout(resolve, 100));
} catch (error) {
console.warn(`[Agent ${agentId}] Cancel failed, continuing with new prompt:`, error);
// Continue anyway - the new prompt might still work
}
}
// Reset message IDs for new turn - ensures each prompt gets fresh responses
agent.currentAssistantMessageId = null;
agent.currentThoughtId = null;
@@ -784,6 +798,7 @@ export class AgentManager {
timestamp: new Date(),
notification: {
type: 'permission',
requestId, // Pass the requestId that we stored in pendingPermissions
request: params,
},
};
+1 -1
View File
@@ -23,7 +23,7 @@ export interface EnrichedSessionNotification extends Omit<SessionNotification, '
*/
export type AgentNotification =
| { type: 'session'; notification: EnrichedSessionNotification }
| { type: 'permission'; request: RequestPermissionRequest }
| { type: 'permission'; requestId: string; request: RequestPermissionRequest }
| { type: 'status'; status: AgentStatus; error?: string };
/**
+2 -2
View File
@@ -178,14 +178,14 @@ export class Session {
type: "agent_permission_request",
payload: {
agentId,
requestId: uuidv4(), // Generate request ID
requestId: notification.requestId, // Use the requestId from AgentManager
sessionId: permissionRequest.sessionId,
toolCall: permissionRequest.toolCall,
options: permissionRequest.options,
},
});
console.log(
`[Session ${this.clientId}] Forwarded permission request for agent ${agentId}`
`[Session ${this.clientId}] Forwarded permission request for agent ${agentId} with requestId ${notification.requestId}`
);
return;
}