Initial commit: RA-H Open Source Edition
Local-first knowledge management system with BYO API keys. Features: - 3-panel UI (Nodes | Focus | Helpers) - SQLite + sqlite-vec for vector search - Agent system (Easy/Hard mode orchestrators) - Content extraction (YouTube, PDF, web) - Integrate workflow for connection discovery - Dimension system with auto-assignment Tech stack: - Next.js 15 + TypeScript + Tailwind CSS - Anthropic (Claude) + OpenAI (GPT) via Vercel AI SDK Setup: npm install && npm rebuild better-sqlite3 scripts/dev/bootstrap-local.sh npm run dev MIT License
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Server-Sent Events (SSE) API Route
|
||||
* Streams real-time database change events to connected clients
|
||||
*/
|
||||
|
||||
import { eventBroadcaster } from '@/services/events';
|
||||
|
||||
export async function GET() {
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
const stream = new ReadableStream({
|
||||
start(controller) {
|
||||
// Add this connection to the broadcaster
|
||||
console.log('🔌 New SSE connection established');
|
||||
eventBroadcaster.addConnection(controller);
|
||||
console.log('📊 Total SSE connections:', eventBroadcaster.getConnectionCount());
|
||||
|
||||
// Send initial connection confirmation
|
||||
const initialMessage = `data: ${JSON.stringify({
|
||||
type: 'CONNECTION_ESTABLISHED',
|
||||
data: { timestamp: Date.now() }
|
||||
})}\n\n`;
|
||||
|
||||
controller.enqueue(encoder.encode(initialMessage));
|
||||
|
||||
// Store controller reference for cleanup
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(controller as any)._cleanup = () => {
|
||||
console.log('🔌 SSE connection cleanup');
|
||||
eventBroadcaster.removeConnection(controller);
|
||||
};
|
||||
},
|
||||
|
||||
cancel(controller) {
|
||||
// Clean up when client disconnects
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
if ((controller as any)._cleanup) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(controller as any)._cleanup();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return new Response(stream, {
|
||||
headers: {
|
||||
'Content-Type': 'text/event-stream',
|
||||
'Cache-Control': 'no-cache, no-transform',
|
||||
'Connection': 'keep-alive',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Headers': 'Cache-Control',
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user