@yeaft/webchat-agent 1.0.40 → 1.0.41

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.
@@ -5,6 +5,7 @@ import { encrypt, decrypt, isEncrypted } from '../encryption.js';
5
5
  // 需要在断连期间缓冲的消息类型(CLI / Session 输出相关的关键消息)
6
6
  export const BUFFERABLE_TYPES = new Set([
7
7
  'claude_output', 'yeaft_output', 'yeaft_session_output', 'session_output',
8
+ 'yeaft_history_chunk',
8
9
  'turn_completed', 'conversation_closed',
9
10
  'session_id_update', 'compact_status', 'slash_commands_update',
10
11
  'background_task_started', 'background_task_output',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "1.0.40",
3
+ "version": "1.0.41",
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",
@@ -4827,6 +4827,110 @@ export async function handleYeaftLoadHistory(msg) {
4827
4827
  sessionId ? store.loadRecentBySession(sessionId, lim) : store.loadRecent(lim);
4828
4828
  let historyAlreadyReplayed = false;
4829
4829
 
4830
+ const replayHistoryFromStore = () => {
4831
+ // Delta path: caller knows the latest seq (or message id) it has cached
4832
+ // and wants only the messages that arrived after that cursor. Returns
4833
+ // mode:'delta' so the frontend can append+dedupe instead of replacing
4834
+ // the pane.
4835
+ const afterSeqRaw = (msg && Number.isFinite(msg.afterSeq)) ? msg.afterSeq : null;
4836
+ const afterMessageId = (msg && typeof msg.afterMessageId === 'string') ? msg.afterMessageId : null;
4837
+ let afterSeq = afterSeqRaw;
4838
+ if (afterSeq === null && afterMessageId && typeof session.conversationStore.getMessageSeqById === 'function') {
4839
+ afterSeq = session.conversationStore.getMessageSeqById(afterMessageId);
4840
+ }
4841
+ if (sessionId && afterSeq !== null && typeof session.conversationStore.loadAfterSeqByGroup === 'function') {
4842
+ const delta = session.conversationStore.loadAfterSeqByGroup(sessionId, afterSeq);
4843
+ const projectedMessages = emitHistoryChunk({
4844
+ sessionId,
4845
+ messages: delta.messages,
4846
+ mode: 'delta',
4847
+ latestSeq: delta.latestSeq,
4848
+ afterSeq,
4849
+ });
4850
+ sendSessionEvent({
4851
+ type: 'history_loaded',
4852
+ mode: 'delta',
4853
+ count: projectedMessages.length,
4854
+ sessionId,
4855
+ latestSeq: delta.latestSeq,
4856
+ afterSeq,
4857
+ });
4858
+ return;
4859
+ }
4860
+
4861
+ // `msg.limit` is the replay-scrollback request from the frontend (UI
4862
+ // history pane, not engine context). Keep the bootstrap window small so
4863
+ // opening a group can paint the latest messages quickly; older rows are
4864
+ // paged via `yeaft_load_more_history` when the user scrolls upward.
4865
+ const limit = (typeof msg.limit === 'number') ? msg.limit : 10;
4866
+ const visiblePage = sessionId
4867
+ ? loadVisibleGroupHistoryPage(session.conversationStore, sessionId, limit)
4868
+ : { messages: limit > 0 ? pickRecent(session.conversationStore, limit) : [], oldestSeq: null, hasMore: false };
4869
+ // Legacy compact.md is a non-group fallback only. For group replay, reading
4870
+ // it makes every group show "has compact" once any legacy/non-scoped compact
4871
+ // exists, even when this group has no scoped summary.
4872
+ const compactSummary = sessionId ? '' : session.conversationStore.readCompactSummary();
4873
+ const replayEntries = sessionId
4874
+ ? visiblePage.messages
4875
+ : visiblePage.messages
4876
+ .map(projectPersistedToVisibleHistoryEntry)
4877
+ .filter(Boolean);
4878
+
4879
+ let latestSeq = null;
4880
+ if (replayEntries.length > 0 && typeof session.conversationStore.getMessageSeqById === 'function') {
4881
+ const last = replayEntries[replayEntries.length - 1];
4882
+ if (last && last.id) latestSeq = session.conversationStore.getMessageSeqById(last.id);
4883
+ }
4884
+
4885
+ if (sessionId) {
4886
+ emitHistoryChunk({
4887
+ sessionId,
4888
+ messages: replayEntries,
4889
+ mode: 'recent',
4890
+ oldestSeq: visiblePage.oldestSeq,
4891
+ hasMore: visiblePage.hasMore,
4892
+ latestSeq,
4893
+ turns: limit,
4894
+ });
4895
+ } else {
4896
+ emitLegacyHistoryOutputFrames(replayEntries);
4897
+ }
4898
+
4899
+ // Compute the pagination cursor for the bootstrap load so the frontend
4900
+ // knows whether a "Load older messages" hint should be shown and where
4901
+ // to start the next page. For group history, this is computed from the
4902
+ // visible projected page, not raw persisted rows, so reflection/internal
4903
+ // tail rows cannot consume the bootstrap window or create false hasMore.
4904
+ let hasMore = false;
4905
+ let oldestSeq = null;
4906
+ if (sessionId) {
4907
+ hasMore = visiblePage.hasMore;
4908
+ oldestSeq = visiblePage.oldestSeq;
4909
+ }
4910
+
4911
+ // hasCompactSummary used to read a single session-global file, so it was
4912
+ // always true once ANY group/VP in the session had compacted. For group
4913
+ // replay, only scoped per-(group, vp) summaries count; legacy compact.md is
4914
+ // reserved for non-group / pre-scoped 1:1 callers.
4915
+ let hasCompactSummaryFlag = !!compactSummary;
4916
+ if (sessionId && typeof session.conversationStore.hasAnyCompactSummaryForSession === 'function') {
4917
+ hasCompactSummaryFlag = session.conversationStore.hasAnyCompactSummaryForSession(sessionId);
4918
+ }
4919
+
4920
+ sendSessionEvent({
4921
+ type: 'history_loaded',
4922
+ mode: 'recent',
4923
+ count: replayEntries.length,
4924
+ hasCompactSummary: hasCompactSummaryFlag,
4925
+ totalHot: session.conversationStore.countHot(),
4926
+ totalCold: session.conversationStore.countCold(),
4927
+ sessionId,
4928
+ hasMore,
4929
+ oldestSeq,
4930
+ latestSeq,
4931
+ });
4932
+ };
4933
+
4830
4934
  if (!session) {
4831
4935
  const yeaftDir = ctx.CONFIG?.yeaftDir || DEFAULT_YEAFT_DIR;
4832
4936
  const afterSeqRaw = (msg && Number.isFinite(msg.afterSeq)) ? msg.afterSeq : null;
@@ -4878,6 +4982,8 @@ export async function handleYeaftLoadHistory(msg) {
4878
4982
  // hydration handles it.
4879
4983
  if (sessionId) setGroupHistory(sessionId, hydrateGroupHistory(sessionId));
4880
4984
  } else {
4985
+ replayHistoryFromStore();
4986
+ historyAlreadyReplayed = true;
4881
4987
  refreshLiveSessionConfig();
4882
4988
  hydrateYeaftStatusFromSession(session, { reason: 'history_load', emitEvent: true });
4883
4989
  }
@@ -4917,107 +5023,7 @@ export async function handleYeaftLoadHistory(msg) {
4917
5023
 
4918
5024
  if (historyAlreadyReplayed) return;
4919
5025
 
4920
- // Delta path: caller knows the latest seq (or message id) it has cached
4921
- // and wants only the messages that arrived after that cursor. Returns
4922
- // early with mode:'delta' so the frontend can append+dedupe instead of
4923
- // replacing the pane.
4924
- const afterSeqRaw = (msg && Number.isFinite(msg.afterSeq)) ? msg.afterSeq : null;
4925
- const afterMessageId = (msg && typeof msg.afterMessageId === 'string') ? msg.afterMessageId : null;
4926
- let afterSeq = afterSeqRaw;
4927
- if (afterSeq === null && afterMessageId && typeof session.conversationStore.getMessageSeqById === 'function') {
4928
- afterSeq = session.conversationStore.getMessageSeqById(afterMessageId);
4929
- }
4930
- if (sessionId && afterSeq !== null && typeof session.conversationStore.loadAfterSeqByGroup === 'function') {
4931
- const delta = session.conversationStore.loadAfterSeqByGroup(sessionId, afterSeq);
4932
- const projectedMessages = emitHistoryChunk({
4933
- sessionId,
4934
- messages: delta.messages,
4935
- mode: 'delta',
4936
- latestSeq: delta.latestSeq,
4937
- afterSeq,
4938
- });
4939
- sendSessionEvent({
4940
- type: 'history_loaded',
4941
- mode: 'delta',
4942
- count: projectedMessages.length,
4943
- sessionId,
4944
- latestSeq: delta.latestSeq,
4945
- afterSeq,
4946
- });
4947
- return;
4948
- }
4949
-
4950
- // `msg.limit` is the replay-scrollback request from the frontend (UI
4951
- // history pane, not engine context). Keep the bootstrap window small so
4952
- // opening a group can paint the latest messages quickly; older rows are
4953
- // paged via `yeaft_load_more_history` when the user scrolls upward.
4954
- const limit = (typeof msg.limit === 'number') ? msg.limit : 10;
4955
- const visiblePage = sessionId
4956
- ? loadVisibleGroupHistoryPage(session.conversationStore, sessionId, limit)
4957
- : { messages: limit > 0 ? pickRecent(session.conversationStore, limit) : [], oldestSeq: null, hasMore: false };
4958
- // Legacy compact.md is a non-group fallback only. For group replay, reading
4959
- // it makes every group show "has compact" once any legacy/non-scoped compact
4960
- // exists, even when this group has no scoped summary.
4961
- const compactSummary = sessionId ? '' : session.conversationStore.readCompactSummary();
4962
- const replayEntries = sessionId
4963
- ? visiblePage.messages
4964
- : visiblePage.messages
4965
- .map(projectPersistedToVisibleHistoryEntry)
4966
- .filter(Boolean);
4967
-
4968
- let latestSeq = null;
4969
- if (replayEntries.length > 0 && typeof session.conversationStore.getMessageSeqById === 'function') {
4970
- const last = replayEntries[replayEntries.length - 1];
4971
- if (last && last.id) latestSeq = session.conversationStore.getMessageSeqById(last.id);
4972
- }
4973
-
4974
- if (sessionId) {
4975
- emitHistoryChunk({
4976
- sessionId,
4977
- messages: replayEntries,
4978
- mode: 'recent',
4979
- oldestSeq: visiblePage.oldestSeq,
4980
- hasMore: visiblePage.hasMore,
4981
- latestSeq,
4982
- turns: limit,
4983
- });
4984
- } else {
4985
- emitLegacyHistoryOutputFrames(replayEntries);
4986
- }
4987
-
4988
- // Compute the pagination cursor for the bootstrap load so the frontend
4989
- // knows whether a "Load older messages" hint should be shown and where
4990
- // to start the next page. For group history, this is computed from the
4991
- // visible projected page, not raw persisted rows, so reflection/internal
4992
- // tail rows cannot consume the bootstrap window or create false hasMore.
4993
- let hasMore = false;
4994
- let oldestSeq = null;
4995
- if (sessionId) {
4996
- hasMore = visiblePage.hasMore;
4997
- oldestSeq = visiblePage.oldestSeq;
4998
- }
4999
-
5000
- // hasCompactSummary used to read a single session-global file, so it was
5001
- // always true once ANY group/VP in the session had compacted. For group
5002
- // replay, only scoped per-(group, vp) summaries count; legacy compact.md is
5003
- // reserved for non-group / pre-scoped 1:1 callers.
5004
- let hasCompactSummaryFlag = !!compactSummary;
5005
- if (sessionId && typeof session.conversationStore.hasAnyCompactSummaryForSession === 'function') {
5006
- hasCompactSummaryFlag = session.conversationStore.hasAnyCompactSummaryForSession(sessionId);
5007
- }
5008
-
5009
- sendSessionEvent({
5010
- type: 'history_loaded',
5011
- mode: 'recent',
5012
- count: replayEntries.length,
5013
- hasCompactSummary: hasCompactSummaryFlag,
5014
- totalHot: session.conversationStore.countHot(),
5015
- totalCold: session.conversationStore.countCold(),
5016
- sessionId,
5017
- hasMore,
5018
- oldestSeq,
5019
- latestSeq,
5020
- });
5026
+ replayHistoryFromStore();
5021
5027
  }
5022
5028
 
5023
5029
  /**