Merge branch 'Youzini-afk:main' into main

This commit is contained in:
Hao19911125
2026-04-06 19:51:37 +08:00
committed by GitHub
2 changed files with 6 additions and 21 deletions

View File

@@ -1791,9 +1791,6 @@ function ensurePersistedRecallRecordForGeneration({
}, },
); );
// #region agent log
{fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({sessionId:'b6ba57',location:'index.js:ensurePersistedRecallRecordForGeneration',message:'target resolved',data:{targetUserMessageIndex,chatLen:chat.length,isUser:chat[targetUserMessageIndex]?.is_user,generationType,hookName:String(hookName||''),injectionTextLen:injectionText?.length||0},timestamp:Date.now()})}).catch(()=>{});}
// #endregion
if ( if (
!Number.isFinite(targetUserMessageIndex) || !Number.isFinite(targetUserMessageIndex) ||
!chat[targetUserMessageIndex]?.is_user !chat[targetUserMessageIndex]?.is_user
@@ -2550,9 +2547,6 @@ function refreshPersistedRecallMessageUi() {
skippedNonUserIndices: [], skippedNonUserIndices: [],
}; };
// #region agent log
{const _latestUserIdx=chat.reduce((a,m,i)=>m?.is_user?i:a,-1);const _domKeys=[...messageElementMap.keys()];const _hasRecord=_latestUserIdx>=0&&!!readPersistedRecallFromUserMessage(chat,_latestUserIdx);const _hasDom=_latestUserIdx>=0&&messageElementMap.has(_latestUserIdx);fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({sessionId:'b6ba57',location:'index.js:refreshPersistedRecallMessageUi:loop-start',message:'refresh loop entry',data:{chatLen:chat.length,domElementCount:_domKeys.length,domKeys:_domKeys.slice(-6),latestUserIdx:_latestUserIdx,hasRecordForLatest:_hasRecord,hasDomForLatest:_hasDom},timestamp:Date.now()})}).catch(()=>{});}
// #endregion
for (let messageIndex = 0; messageIndex < chat.length; messageIndex++) { for (let messageIndex = 0; messageIndex < chat.length; messageIndex++) {
const message = chat[messageIndex]; const message = chat[messageIndex];
const messageElement = messageElementMap.get(messageIndex) || null; const messageElement = messageElementMap.get(messageIndex) || null;
@@ -2584,9 +2578,6 @@ function refreshPersistedRecallMessageUi() {
} }
const record = readPersistedRecallFromUserMessage(chat, messageIndex); const record = readPersistedRecallFromUserMessage(chat, messageIndex);
// #region agent log
if(message?.is_user){const _isLatestUser=messageIndex===chat.reduce((a,m,i)=>m?.is_user?i:a,-1);if(_isLatestUser){fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({sessionId:'b6ba57',location:'index.js:refreshPersistedRecallMessageUi:latest-user-check',message:'latest user msg detail',data:{messageIndex,hasRecord:!!record?.injectionText,hasDom:!!messageElement,hasExistingCard:!!existingCard,domMesid:messageElement?.getAttribute?.('mesid'),domDataMesid:messageElement?.getAttribute?.('data-mesid'),domClasses:messageElement?.className?.slice(0,80)||''},timestamp:Date.now()})}).catch(()=>{});}}
// #endregion
if (!record?.injectionText) { if (!record?.injectionText) {
if (messageElement) { if (messageElement) {
restoreRecallCardUserInputDisplay(messageElement); restoreRecallCardUserInputDisplay(messageElement);
@@ -2654,9 +2645,6 @@ function refreshPersistedRecallMessageUi() {
recallCardUserInputDisplayMode, recallCardUserInputDisplayMode,
); );
summary.renderedCount += 1; summary.renderedCount += 1;
// #region agent log
{const _isLatestUser2=messageIndex===chat.reduce((a,m,i)=>m?.is_user?i:a,-1);if(_isLatestUser2){fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({sessionId:'b6ba57',location:'index.js:refreshPersistedRecallMessageUi:card-mounted',message:'card mounted for latest user',data:{messageIndex,hadExistingCard:!!currentCard,cardInDom:!!messageElement.querySelector('.bme-recall-card')},timestamp:Date.now()})}).catch(()=>{});}}
// #endregion
} }
summary.status = summarizePersistedRecallRefreshStatus(summary); summary.status = summarizePersistedRecallRefreshStatus(summary);
@@ -2673,9 +2661,6 @@ function refreshPersistedRecallMessageUi() {
`rendered:${summary.renderedCount}`, `rendered:${summary.renderedCount}`,
); );
} }
// #region agent log
fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({sessionId:'b6ba57',location:'index.js:refreshPersistedRecallMessageUi:summary',message:'refresh complete',data:{status:summary.status,renderedCount:summary.renderedCount,persistedRecordCount:summary.persistedRecordCount,waitingDom:summary.waitingMessageIndices,anchorFail:summary.anchorFailureIndices},timestamp:Date.now()})}).catch(()=>{});
// #endregion
return summary; return summary;
} }
@@ -2767,9 +2752,6 @@ function armPersistedRecallMessageUiObserver(sessionId, runAttempt) {
} }
function schedulePersistedRecallMessageUiRefresh(delayMs = 0) { function schedulePersistedRecallMessageUiRefresh(delayMs = 0) {
// #region agent log
{const _prevSession=persistedRecallUiRefreshSession;const _caller=new Error().stack?.split('\n')?.[2]?.trim()?.slice(0,120)||'';fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({sessionId:'b6ba57',location:'index.js:schedulePersistedRecallMessageUiRefresh',message:'schedule called',data:{delayMs,prevSession:_prevSession,nextSession:_prevSession+1,caller:_caller},timestamp:Date.now()})}).catch(()=>{});}
// #endregion
clearTimeout(persistedRecallUiRefreshTimer); clearTimeout(persistedRecallUiRefreshTimer);
clearPersistedRecallMessageUiObserver(); clearPersistedRecallMessageUiObserver();
@@ -2792,8 +2774,9 @@ function schedulePersistedRecallMessageUiRefresh(delayMs = 0) {
summary.status === "missing_message_anchor") && summary.status === "missing_message_anchor") &&
attemptIndex < retryDelays.length - 1; attemptIndex < retryDelays.length - 1;
const shouldWatchForRepaint = // 勿在「已成功渲染」时长期挂 MutationObserver#chat 上 class/流式更新会疯狂触发
summary.status === "rendered" && summary.renderedCount > 0; // runAttempt造成满屏刷新与日志显式事件USER_MESSAGE_RENDERED 等)仍会 schedule 刷新。
const shouldWatchForRepaint = false;
if (!shouldRetryForPending && !shouldWatchForRepaint) { if (!shouldRetryForPending && !shouldWatchForRepaint) {
clearPersistedRecallMessageUiObserver(); clearPersistedRecallMessageUiObserver();

View File

@@ -134,11 +134,13 @@ export function resolveGenerationTargetUserMessageIndex(
const normalizedType = String(generationType || "normal").trim() || "normal"; const normalizedType = String(generationType || "normal").trim() || "normal";
// normal取「最后一条非系统用户楼层」。若直接 return 末条非 user常见为刚追加的助手回合
// 会得到 null导致持久化无法回绑到本轮 user`hasRecordForLatest` 长期为 false。
if (normalizedType === "normal") { if (normalizedType === "normal") {
for (let index = chat.length - 1; index >= 0; index--) { for (let index = chat.length - 1; index >= 0; index--) {
const message = chat[index]; const message = chat[index];
if (message?.is_system) continue; if (message?.is_system) continue;
return message?.is_user ? index : null; if (message?.is_user) return index;
} }
return null; return null;
} }