@yeaft/webchat-agent 0.1.1102 → 0.1.1104

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "0.1.1102",
3
+ "version": "0.1.1104",
4
4
  "description": "Remote worker agent for Yeaft Web Code Agent — connects the native Yeaft engine, CLI providers, and workbench tools",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -777,11 +777,13 @@ function ensureYeaftConversationId() {
777
777
 
778
778
  function projectVisibleHistoryChunkMessages(messages = []) {
779
779
  return (messages || [])
780
+ .map(projectPersistedToVisibleHistoryEntry)
781
+ .filter(Boolean)
780
782
  .map(m => ({
781
783
  ...(m.id ? { id: m.id } : {}),
782
784
  role: m.role,
783
785
  content: m.content,
784
- ts: m.ts || m.time || null,
786
+ ts: m.ts || null,
785
787
  sessionId: m.sessionId || null,
786
788
  threadId: m.threadId || m.turnId || 'main',
787
789
  turnId: m.turnId || m.threadId || 'main',
@@ -794,18 +796,20 @@ function projectVisibleHistoryChunkMessages(messages = []) {
794
796
  }
795
797
 
796
798
  function emitHistoryChunk({ sessionId, messages, mode = 'older', oldestSeq = null, hasMore = false, latestSeq = null, afterSeq = null, turns = null }) {
799
+ const projectedMessages = projectVisibleHistoryChunkMessages(messages);
797
800
  sendToServer({
798
801
  type: 'yeaft_history_chunk',
799
802
  conversationId: yeaftConversationId,
800
803
  sessionId,
801
804
  mode,
802
- messages: projectVisibleHistoryChunkMessages(messages),
805
+ messages: projectedMessages,
803
806
  oldestSeq,
804
807
  hasMore: !!hasMore,
805
808
  latestSeq,
806
809
  afterSeq,
807
810
  turns,
808
811
  });
812
+ return projectedMessages;
809
813
  }
810
814
 
811
815
  function emitLegacyHistoryOutputFrames(replayEntries) {
@@ -1355,6 +1359,7 @@ async function routeEnvelopeToVpThread(sessionId, vpId, envelope) {
1355
1359
  speakerVpId: envelope?.msg?.meta?.senderVpId || envelope?.msg?.from || null,
1356
1360
  attachments: Array.isArray(envelope?.msg?.meta?.attachments) ? envelope.msg.meta.attachments : [],
1357
1361
  internal: isInternalAppend,
1362
+ ts: envelope?.msg?.ts || null,
1358
1363
  });
1359
1364
  thread.updatedAt = Date.now();
1360
1365
  try {
@@ -1451,6 +1456,7 @@ function ensureDriverRunning(sessionId, vpId, threadId = 'main') {
1451
1456
  speakerVpId: senderVpId,
1452
1457
  attachments: Array.isArray(meta.attachments) ? meta.attachments : [],
1453
1458
  internal: isInternal,
1459
+ ts: envelope?.msg?.ts || null,
1454
1460
  });
1455
1461
  }
1456
1462
  } catch { /* never crash WS pipeline */ }
@@ -3736,11 +3742,11 @@ function appendTurnToSessionHistory(sessionId, threadId, vpId, prompts, assistan
3736
3742
  * refresh replay can render chips without leaking image source data into
3737
3743
  * the message body.
3738
3744
  *
3739
- * @param {{ msgId:string, text:string, sessionId:string, role?:string, speakerVpId?:string|null, attachments?:Array<object>, internal?:boolean }} args
3745
+ * @param {{ msgId:string, text:string, sessionId:string, role?:string, speakerVpId?:string|null, attachments?:Array<object>, internal?:boolean, ts?:string|null }} args
3740
3746
  * @returns {boolean} true if this call wrote the row, false if a prior
3741
3747
  * call already wrote it (dedup hit).
3742
3748
  */
3743
- function persistInboundMessageOnceByMsgId({ msgId, text, sessionId, threadId = 'main', role, speakerVpId, attachments, internal = false }) {
3749
+ function persistInboundMessageOnceByMsgId({ msgId, text, sessionId, threadId = 'main', role, speakerVpId, attachments, internal = false, ts = null }) {
3744
3750
  if (!session?.conversationStore) return false;
3745
3751
  // No msgId means no dedup key — caller is responsible for guarding.
3746
3752
  // Both call sites already do (`if (envMsgId && text)` and
@@ -3795,6 +3801,9 @@ function persistInboundMessageOnceByMsgId({ msgId, text, sessionId, threadId = '
3795
3801
  if (persistRole === 'user' && Array.isArray(attachments) && attachments.length > 0) {
3796
3802
  record.attachments = attachments;
3797
3803
  }
3804
+ if (ts && typeof ts === 'string') {
3805
+ record.time = ts;
3806
+ }
3798
3807
  session.conversationStore.append(record);
3799
3808
  return true;
3800
3809
  } catch (err) {
@@ -4557,14 +4566,14 @@ export async function handleYeaftLoadHistory(msg) {
4557
4566
  const delta = afterSeq !== null && typeof coldStore.loadAfterSeqByGroup === 'function'
4558
4567
  ? coldStore.loadAfterSeqByGroup(sessionId, afterSeq)
4559
4568
  : { messages: [], latestSeq: null };
4560
- emitHistoryChunk({
4569
+ const projectedMessages = emitHistoryChunk({
4561
4570
  sessionId,
4562
4571
  messages: delta.messages,
4563
4572
  mode: 'delta',
4564
4573
  latestSeq: delta.latestSeq,
4565
4574
  afterSeq,
4566
4575
  });
4567
- sendSessionEvent({ type: 'history_loaded', mode: 'delta', count: delta.messages.length, sessionId, latestSeq: delta.latestSeq, afterSeq });
4576
+ sendSessionEvent({ type: 'history_loaded', mode: 'delta', count: projectedMessages.length, sessionId, latestSeq: delta.latestSeq, afterSeq });
4568
4577
  } else {
4569
4578
  emitVisibleHistoryReplay({ store: coldStore, sessionId, limit, mode: 'recent' });
4570
4579
  }
@@ -4639,7 +4648,7 @@ export async function handleYeaftLoadHistory(msg) {
4639
4648
  }
4640
4649
  if (sessionId && afterSeq !== null && typeof session.conversationStore.loadAfterSeqByGroup === 'function') {
4641
4650
  const delta = session.conversationStore.loadAfterSeqByGroup(sessionId, afterSeq);
4642
- emitHistoryChunk({
4651
+ const projectedMessages = emitHistoryChunk({
4643
4652
  sessionId,
4644
4653
  messages: delta.messages,
4645
4654
  mode: 'delta',
@@ -4649,7 +4658,7 @@ export async function handleYeaftLoadHistory(msg) {
4649
4658
  sendSessionEvent({
4650
4659
  type: 'history_loaded',
4651
4660
  mode: 'delta',
4652
- count: delta.messages.length,
4661
+ count: projectedMessages.length,
4653
4662
  sessionId,
4654
4663
  latestSeq: delta.latestSeq,
4655
4664
  afterSeq,
@@ -5102,6 +5111,7 @@ export async function handleYeaftMcpReload(msg = {}) {
5102
5111
 
5103
5112
  export const __testHooks = {
5104
5113
  loadVisibleGroupHistoryPage,
5114
+ persistInboundMessageOnceByMsgId,
5105
5115
  setSessionForTest(nextSession) {
5106
5116
  session = nextSession || null;
5107
5117
  },