Phase 2 scaffold: mitra online status & pairing logic

Add mitra online/offline status with heartbeat-based auto-offline,
customer-mitra pairing via Valkey pub/sub blast, session management,
and control center dashboard with real-time stats.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-05 23:17:49 +08:00
parent a7a2a32d27
commit d668112edd
44 changed files with 2800 additions and 80 deletions

View File

@@ -0,0 +1,47 @@
import Redis from 'ioredis'
let pub
let sub
let client
export const getValkeyClient = () => {
if (!client) {
const url = process.env.VALKEY_URL || 'redis://localhost:6379'
client = new Redis(url)
}
return client
}
export const getValkeyPub = () => {
if (!pub) {
const url = process.env.VALKEY_URL || 'redis://localhost:6379'
pub = new Redis(url)
}
return pub
}
export const getValkeySub = () => {
if (!sub) {
const url = process.env.VALKEY_URL || 'redis://localhost:6379'
sub = new Redis(url)
}
return sub
}
export const publish = async (channel, data) => {
const pubClient = getValkeyPub()
await pubClient.publish(channel, JSON.stringify(data))
}
export const subscribe = (channel, callback) => {
const subClient = getValkeySub()
subClient.subscribe(channel)
subClient.on('message', (ch, message) => {
if (ch === channel) {
callback(JSON.parse(message))
}
})
return () => {
subClient.unsubscribe(channel)
}
}