batch3 T3: broker user channel + /api/ws/user + project/session/inference emits

- broker.subscribeUser/publishUser via separate user topics map
- /api/ws/user WS route subscribes to the user channel
- projects/sessions POST/DELETE handlers emit lifecycle frames
- inference 3 terminal-state sites emit session_updated with RETURNING

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-15 15:06:31 +00:00
parent d88b3348a2
commit 8fc525eab9
7 changed files with 132 additions and 50 deletions

View File

@@ -43,4 +43,23 @@ export function registerWebSocket(
socket.on('error', () => unsubscribe());
}
);
app.get('/api/ws/user', { websocket: true }, async (socket, req) => {
const user = req.user;
if (!user) {
socket.close(1008, 'unauthenticated');
return;
}
// No snapshot — user channel is purely live updates.
const unsubscribe = broker.subscribeUser(user, (frame) => {
if (socket.readyState !== socket.OPEN) return;
try {
socket.send(JSON.stringify(frame));
} catch (err) {
app.log.warn({ err, user }, 'user ws send failed');
}
});
socket.on('close', () => unsubscribe());
socket.on('error', () => unsubscribe());
});
}