Advanced SSE Integration
Collaboration-Specific Event Processing
Extend your existing EventSource handling to process collaboration events:Copy
class EnhancedSSEClient {
constructor(threadId, apiKey, userId) {
this.threadId = threadId;
this.apiKey = apiKey;
this.userId = userId;
this.collaborationManager = new CollaborationManager();
this.setupEventSource();
}
setupEventSource() {
// Build upon existing SSE setup from API Integration Guide
this.eventSource = new EventSource(`/api/assistants/threads/${this.threadId}/messages/stream`, {
headers: {
'Authorization': `Bearer ${this.apiKey}`,
'X-Envole-User-Id': this.userId
}
});
this.eventSource.onmessage = (event) => {
const data = JSON.parse(event.data);
// Handle collaboration events
if (this.isCollaborationEvent(data.type)) {
this.collaborationManager.handleSSEEvent(data);
}
// Continue with existing event handling for other events
this.handleStandardEvents(data);
};
}
isCollaborationEvent(eventType) {
const collaborationEvents = [
'NOTIFICATION_REQUEST_ORCHESTRATION_COLLABORATION_REQUEST',
'NOTIFICATION_PLAN_ORCHESTRATION_COLLABORATION_PLANNING_INITIATED',
'NOTIFICATION_PLAN_ORCHESTRATION_COLLABORATION_PLANNING_IN_PROGRESS',
'NOTIFICATION_PLAN_ORCHESTRATION_COLLABORATION_PLANNING_COMPLETED',
'NOTIFICATION_MULTI_ASSISTANT_COLLABORATION_STARTED',
'NOTIFICATION_MULTI_ASSISTANT_COLLABORATION_ASSISTANT_RESPONSE_IN_PROGRESS',
'NOTIFICATION_MULTI_ASSISTANT_COLLABORATION_ASSISTANT_RESPONSE_COMPLETED',
'NOTIFICATION_MULTI_ASSISTANT_COLLABORATION_COMPLETED',
'NOTIFICATION_MULTI_ASSISTANT_COLLABORATION_UNIFIED_RESPONSE_STARTED',
'NOTIFICATION_MULTI_ASSISTANT_COLLABORATION_NO_UNIFIED_RESPONSE_REQUIRED',
'NOTIFICATION_MULTI_ASSISTANT_COLLABORATION_FAILED',
'ERROR_INVALID_COLLABORATION_REQUEST'
];
return collaborationEvents.includes(eventType);
}
handleStandardEvents(data) {
// Your existing event handling from API Integration Guide
// AGENT_RESPONSE_CHUNK, AGENT_RESPONSE_COMPLETE, etc.
}
}