@adhdev/daemon-standalone 0.9.63 → 0.9.64
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/dist/index.js
CHANGED
|
@@ -40110,9 +40110,34 @@ ${effect.notification.body || ""}`.trim();
|
|
|
40110
40110
|
}
|
|
40111
40111
|
return -1;
|
|
40112
40112
|
}
|
|
40113
|
+
function isReadChatConversationAnchorMessage(message) {
|
|
40114
|
+
if (!message) return false;
|
|
40115
|
+
const role = String(message.role || "").trim().toLowerCase();
|
|
40116
|
+
if (role !== "user" && role !== "assistant") return false;
|
|
40117
|
+
const kind = String(message.kind || "standard").trim().toLowerCase();
|
|
40118
|
+
return !kind || kind === "standard";
|
|
40119
|
+
}
|
|
40120
|
+
function buildVisibleReadChatTailMessages(messages, tailLimit) {
|
|
40121
|
+
const totalMessages = messages.length;
|
|
40122
|
+
if (tailLimit <= 0 || totalMessages <= tailLimit) return messages;
|
|
40123
|
+
const tailMessages = messages.slice(-tailLimit);
|
|
40124
|
+
if (tailMessages.some(isReadChatConversationAnchorMessage)) return tailMessages;
|
|
40125
|
+
const hiddenMessages = messages.slice(0, totalMessages - tailLimit);
|
|
40126
|
+
const anchors = [];
|
|
40127
|
+
const seenRoles = /* @__PURE__ */ new Set();
|
|
40128
|
+
for (let index = hiddenMessages.length - 1; index >= 0 && anchors.length < 2; index -= 1) {
|
|
40129
|
+
const message = hiddenMessages[index];
|
|
40130
|
+
if (!isReadChatConversationAnchorMessage(message)) continue;
|
|
40131
|
+
const role = String(message.role || "").trim().toLowerCase();
|
|
40132
|
+
if (seenRoles.has(role)) continue;
|
|
40133
|
+
seenRoles.add(role);
|
|
40134
|
+
anchors.unshift(message);
|
|
40135
|
+
}
|
|
40136
|
+
return anchors.length > 0 ? [...anchors, ...tailMessages] : tailMessages;
|
|
40137
|
+
}
|
|
40113
40138
|
function buildBoundedTailSync(messages, cursor) {
|
|
40114
40139
|
const totalMessages = messages.length;
|
|
40115
|
-
const tailMessages =
|
|
40140
|
+
const tailMessages = buildVisibleReadChatTailMessages(messages, cursor.tailLimit);
|
|
40116
40141
|
return {
|
|
40117
40142
|
syncMode: "full",
|
|
40118
40143
|
replaceFrom: 0,
|
|
@@ -40234,8 +40259,8 @@ ${effect.notification.body || ""}`.trim();
|
|
|
40234
40259
|
const messages = collapseReplayDuplicatesFromReadChat(normalizeReadChatMessages(validatedPayload));
|
|
40235
40260
|
const cursor = normalizeReadChatCursor(args);
|
|
40236
40261
|
if (!cursor.knownMessageCount && !cursor.lastMessageSignature && cursor.tailLimit > 0 && messages.length > cursor.tailLimit) {
|
|
40237
|
-
const tailMessages = messages
|
|
40238
|
-
const lastMessageSignature = getChatMessageSignature(
|
|
40262
|
+
const tailMessages = buildVisibleReadChatTailMessages(messages, cursor.tailLimit);
|
|
40263
|
+
const lastMessageSignature = getChatMessageSignature(messages[messages.length - 1]);
|
|
40239
40264
|
return {
|
|
40240
40265
|
success: true,
|
|
40241
40266
|
...validatedPayload,
|