@yeaft/webchat-agent 0.1.999 → 0.1.1000
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/yeaft/web-bridge.js +41 -2
package/package.json
CHANGED
package/yeaft/web-bridge.js
CHANGED
|
@@ -1494,15 +1494,54 @@ export function handleYeaftVpRead(msg) {
|
|
|
1494
1494
|
/**
|
|
1495
1495
|
* Session CRUD wired to WS events.
|
|
1496
1496
|
*/
|
|
1497
|
+
function decorateSessionsWithRuntimeState(sessions) {
|
|
1498
|
+
const rows = Array.isArray(sessions) ? sessions : [];
|
|
1499
|
+
if (rows.length === 0) return rows;
|
|
1500
|
+
let statuses = [];
|
|
1501
|
+
try {
|
|
1502
|
+
statuses = getVpStatusBroker().snapshot();
|
|
1503
|
+
} catch {
|
|
1504
|
+
statuses = [];
|
|
1505
|
+
}
|
|
1506
|
+
const bySession = new Map();
|
|
1507
|
+
for (const status of statuses) {
|
|
1508
|
+
const sessionId = status?.sessionId || status?.groupId || null;
|
|
1509
|
+
if (!sessionId) continue;
|
|
1510
|
+
const state = status.state || 'idle';
|
|
1511
|
+
const running = !['idle', 'offline', 'completed', 'failed', 'aborted'].includes(state);
|
|
1512
|
+
const updatedAt = status.updatedAt || status.since || Date.now();
|
|
1513
|
+
const prev = bySession.get(sessionId) || { running: false, runningVpCount: 0, latestActivityAt: 0 };
|
|
1514
|
+
if (running) prev.runningVpCount += 1;
|
|
1515
|
+
prev.running = prev.running || running;
|
|
1516
|
+
prev.latestActivityAt = Math.max(prev.latestActivityAt || 0, updatedAt || 0);
|
|
1517
|
+
bySession.set(sessionId, prev);
|
|
1518
|
+
}
|
|
1519
|
+
return rows.map(session => {
|
|
1520
|
+
if (!session || !session.id) return session;
|
|
1521
|
+
const runtime = bySession.get(session.id);
|
|
1522
|
+
if (!runtime) return { ...session, running: false, active: false };
|
|
1523
|
+
return {
|
|
1524
|
+
...session,
|
|
1525
|
+
running: !!runtime.running,
|
|
1526
|
+
active: !!runtime.running,
|
|
1527
|
+
runningVpCount: runtime.runningVpCount || 0,
|
|
1528
|
+
latestActivityAt: runtime.latestActivityAt || null,
|
|
1529
|
+
};
|
|
1530
|
+
});
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1497
1533
|
function sendSessionCrudResult(payload) {
|
|
1498
|
-
|
|
1534
|
+
const next = payload && payload.ok && Array.isArray(payload.sessions)
|
|
1535
|
+
? { ...payload, sessions: decorateSessionsWithRuntimeState(payload.sessions) }
|
|
1536
|
+
: payload;
|
|
1537
|
+
sendSessionEvent({ type: 'session_crud_result', ...next });
|
|
1499
1538
|
}
|
|
1500
1539
|
|
|
1501
1540
|
function sendSessionSnapshotBroadcast() {
|
|
1502
1541
|
try {
|
|
1503
1542
|
const yeaftDir = ctx.CONFIG?.yeaftDir;
|
|
1504
1543
|
if (!yeaftDir) return;
|
|
1505
|
-
const sessions = snapshotSessions(yeaftDir);
|
|
1544
|
+
const sessions = decorateSessionsWithRuntimeState(snapshotSessions(yeaftDir));
|
|
1506
1545
|
sendSessionEvent({ type: 'session_list_updated', sessions });
|
|
1507
1546
|
} catch (err) {
|
|
1508
1547
|
console.warn('[Yeaft] sendSessionSnapshotBroadcast failed:', err?.message || err);
|