@adhdev/daemon-core 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
|
@@ -12342,9 +12342,34 @@ function findLastMessageIndexBySignature(messages, signature) {
|
|
|
12342
12342
|
}
|
|
12343
12343
|
return -1;
|
|
12344
12344
|
}
|
|
12345
|
+
function isReadChatConversationAnchorMessage(message) {
|
|
12346
|
+
if (!message) return false;
|
|
12347
|
+
const role = String(message.role || "").trim().toLowerCase();
|
|
12348
|
+
if (role !== "user" && role !== "assistant") return false;
|
|
12349
|
+
const kind = String(message.kind || "standard").trim().toLowerCase();
|
|
12350
|
+
return !kind || kind === "standard";
|
|
12351
|
+
}
|
|
12352
|
+
function buildVisibleReadChatTailMessages(messages, tailLimit) {
|
|
12353
|
+
const totalMessages = messages.length;
|
|
12354
|
+
if (tailLimit <= 0 || totalMessages <= tailLimit) return messages;
|
|
12355
|
+
const tailMessages = messages.slice(-tailLimit);
|
|
12356
|
+
if (tailMessages.some(isReadChatConversationAnchorMessage)) return tailMessages;
|
|
12357
|
+
const hiddenMessages = messages.slice(0, totalMessages - tailLimit);
|
|
12358
|
+
const anchors = [];
|
|
12359
|
+
const seenRoles = /* @__PURE__ */ new Set();
|
|
12360
|
+
for (let index = hiddenMessages.length - 1; index >= 0 && anchors.length < 2; index -= 1) {
|
|
12361
|
+
const message = hiddenMessages[index];
|
|
12362
|
+
if (!isReadChatConversationAnchorMessage(message)) continue;
|
|
12363
|
+
const role = String(message.role || "").trim().toLowerCase();
|
|
12364
|
+
if (seenRoles.has(role)) continue;
|
|
12365
|
+
seenRoles.add(role);
|
|
12366
|
+
anchors.unshift(message);
|
|
12367
|
+
}
|
|
12368
|
+
return anchors.length > 0 ? [...anchors, ...tailMessages] : tailMessages;
|
|
12369
|
+
}
|
|
12345
12370
|
function buildBoundedTailSync(messages, cursor) {
|
|
12346
12371
|
const totalMessages = messages.length;
|
|
12347
|
-
const tailMessages =
|
|
12372
|
+
const tailMessages = buildVisibleReadChatTailMessages(messages, cursor.tailLimit);
|
|
12348
12373
|
return {
|
|
12349
12374
|
syncMode: "full",
|
|
12350
12375
|
replaceFrom: 0,
|
|
@@ -12466,8 +12491,8 @@ function buildReadChatCommandResult(payload, args) {
|
|
|
12466
12491
|
const messages = collapseReplayDuplicatesFromReadChat(normalizeReadChatMessages(validatedPayload));
|
|
12467
12492
|
const cursor = normalizeReadChatCursor(args);
|
|
12468
12493
|
if (!cursor.knownMessageCount && !cursor.lastMessageSignature && cursor.tailLimit > 0 && messages.length > cursor.tailLimit) {
|
|
12469
|
-
const tailMessages = messages
|
|
12470
|
-
const lastMessageSignature = getChatMessageSignature(
|
|
12494
|
+
const tailMessages = buildVisibleReadChatTailMessages(messages, cursor.tailLimit);
|
|
12495
|
+
const lastMessageSignature = getChatMessageSignature(messages[messages.length - 1]);
|
|
12471
12496
|
return {
|
|
12472
12497
|
success: true,
|
|
12473
12498
|
...validatedPayload,
|