@yeaft/webchat-agent 1.0.194 → 1.0.196

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.
@@ -33,6 +33,55 @@ export function decorateYeaftSessionsWithPinned(agentId, sessions) {
33
33
  });
34
34
  }
35
35
 
36
+ function syncYeaftSessionMetadata(agentId, agent, event) {
37
+ if (!event || typeof event !== 'object') return event;
38
+ const ownerId = agent?.ownerId || null;
39
+
40
+ if (event.type === 'session_list_updated') {
41
+ const rows = Array.isArray(event.sessions) ? event.sessions : [];
42
+ try {
43
+ if (ownerId) yeaftSessionDb.reconcileFromSnapshot(ownerId, agentId, rows);
44
+ } catch (e) {
45
+ console.warn(`[Server] yeaft session persist failed for agent ${agentId}:`, e?.message || e);
46
+ }
47
+ return { ...event, sessions: decorateYeaftSessionsWithPinned(agentId, rows) };
48
+ }
49
+
50
+ if (event.type !== 'session_crud_result') return event;
51
+ const op = event.op;
52
+ const sessionId = event.sessionId;
53
+ if (event.ok && op === 'list' && Array.isArray(event.sessions)) {
54
+ try {
55
+ if (ownerId) yeaftSessionDb.reconcileFromSnapshot(ownerId, agentId, event.sessions);
56
+ } catch (e) {
57
+ console.warn(`[Server] yeaft session list persist failed for agent ${agentId}:`, e?.message || e);
58
+ }
59
+ return { ...event, sessions: decorateYeaftSessionsWithPinned(agentId, event.sessions) };
60
+ }
61
+ if (!event.ok || !ownerId || !sessionId || (op !== 'archive' && op !== 'delete')) return event;
62
+
63
+ if (op === 'archive') {
64
+ try {
65
+ yeaftSessionDb.setArchivedForAgent(ownerId, agentId, sessionId, true);
66
+ } catch (e) {
67
+ console.warn('[Server] Yeaft Session metadata archive failed:', e?.message || e);
68
+ }
69
+ return event;
70
+ }
71
+
72
+ try {
73
+ yeaftSessionDb.deleteForAgent(ownerId, agentId, sessionId);
74
+ } catch (e) {
75
+ console.warn('[Server] Yeaft Session metadata cleanup failed:', e?.message || e);
76
+ }
77
+ try {
78
+ yeaftAssetStore.deleteScope({ ownerId, agentId, sessionId });
79
+ } catch (e) {
80
+ console.warn('[Server] Yeaft asset cleanup failed:', e?.message || e);
81
+ }
82
+ return event;
83
+ }
84
+
36
85
  function hydrateMessagePreviewData(message) {
37
86
  const attachments = message?.attachments;
38
87
  if (!Array.isArray(attachments) || attachments.length === 0) return message;
@@ -462,8 +511,9 @@ export async function handleAgentOutput(agentId, agent, msg) {
462
511
  case 'yeaft_session_output':
463
512
  case 'session_output': {
464
513
  const data = hydrateInlinePreviewData(msg.data);
465
- if (msg.event?.type === 'yeaft_status') {
466
- agent.yeaftStatus = msg.event;
514
+ const event = syncYeaftSessionMetadata(agentId, agent, msg.event);
515
+ if (event?.type === 'yeaft_status') {
516
+ agent.yeaftStatus = event;
467
517
  await broadcastAgentList();
468
518
  }
469
519
  if (msg.perfTraceId) {
@@ -521,7 +571,7 @@ export async function handleAgentOutput(agentId, agent, msg) {
521
571
  ...(msg.turnId != null ? { turnId: msg.turnId } : {}),
522
572
  ...(msg.threadId != null ? { threadId: msg.threadId } : {}),
523
573
  data,
524
- event: msg.event,
574
+ event,
525
575
  });
526
576
  if (msg.perfTraceId) {
527
577
  recordPerfTraceEvent({
@@ -705,14 +755,6 @@ export async function handleAgentOutput(agentId, agent, msg) {
705
755
  // their agents (online or not) and survive reload. Pure shadow
706
756
  // store — agent's on-disk `~/.yeaft/sessions/` remains canonical.
707
757
  // Forwarding to the web continues unchanged below.
708
- try {
709
- const rows = Array.isArray(msg.sessions) ? msg.sessions : [];
710
- if (agent.ownerId) {
711
- yeaftSessionDb.reconcileFromSnapshot(agent.ownerId, agentId, rows);
712
- }
713
- } catch (e) {
714
- console.warn(`[Server] yeaft session persist failed for agent ${agentId}:`, e?.message || e);
715
- }
716
758
  // fix-yeaft-session-list-and-menu: decorate the outgoing snapshot
717
759
  // with the server-side pin state. The agent has no notion of
718
760
  // pinning (pin is UI metadata that lives in the `yeaft_sessions`
@@ -723,7 +765,8 @@ export async function handleAgentOutput(agentId, agent, msg) {
723
765
  // Use one batch read (`getByAgent`) and a Set lookup instead of an
724
766
  // N+1 `get(id)` per row — relays this size hot path on every
725
767
  // snapshot per connected client.
726
- const decoratedSessions = decorateYeaftSessionsWithPinned(agentId, msg.sessions);
768
+ const syncedEvent = syncYeaftSessionMetadata(agentId, agent, msg);
769
+ const decoratedSessions = syncedEvent.sessions;
727
770
  // Relay verbatim to web (agentId stamped so the web sessions store
728
771
  // can merge per-agent rosters).
729
772
  for (const [, c] of webClients) {
@@ -787,32 +830,7 @@ export async function handleAgentOutput(agentId, agent, msg) {
787
830
  // probes too: entering Yeaft asks each connected agent for its opened
788
831
  // sessions, and that response must carry persisted server-side pin
789
832
  // state before it hits the web store.
790
- let outboundMsg = msg;
791
- try {
792
- const op = msg.op;
793
- const sessionId = msg.sessionId;
794
- if (msg.ok && op === 'list' && Array.isArray(msg.sessions)) {
795
- if (agent.ownerId) yeaftSessionDb.reconcileFromSnapshot(agent.ownerId, agentId, msg.sessions);
796
- outboundMsg = { ...msg, sessions: decorateYeaftSessionsWithPinned(agentId, msg.sessions) };
797
- } else if (msg.ok && sessionId && (op === 'delete' || op === 'archive')) {
798
- if (op === 'archive') {
799
- yeaftSessionDb.setArchivedForAgent(agent.ownerId, agentId, sessionId, true);
800
- } else {
801
- try {
802
- yeaftSessionDb.deleteForAgent(agent.ownerId, agentId, sessionId);
803
- } catch (e) {
804
- console.warn('[Server] Yeaft Session metadata cleanup failed:', e?.message || e);
805
- }
806
- try {
807
- yeaftAssetStore.deleteScope({ ownerId: agent.ownerId, agentId, sessionId });
808
- } catch (e) {
809
- console.warn('[Server] Yeaft asset cleanup failed:', e?.message || e);
810
- }
811
- }
812
- }
813
- } catch (e) {
814
- console.warn(`[Server] yeaft crud-result persist failed:`, e?.message || e);
815
- }
833
+ const outboundMsg = syncYeaftSessionMetadata(agentId, agent, msg);
816
834
  for (const [, c] of webClients) {
817
835
  if (c.authenticated && (CONFIG.skipAuth || c.userId === agent.ownerId)) {
818
836
  await sendToWebClient(c, { ...outboundMsg, agentId: agentId });
@@ -1 +1 @@
1
- {"version":"1.0.194"}
1
+ {"version":"1.0.196"}