@ccpocket/bridge 1.67.3 → 1.68.0

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/websocket.js CHANGED
@@ -999,13 +999,58 @@ export class BridgeWebSocketServer {
999
999
  }
1000
1000
  this.seedCodexCanonicalUserTurnUuidMap(session, history);
1001
1001
  let nextSeq = canonicalEntries.at(-1)?.seq ?? 0;
1002
+ const canonicalAssistantContentsByUser = new Map();
1003
+ let canonicalUserKey = null;
1004
+ for (const entry of canonicalEntries) {
1005
+ if (entry.message.type === "user_input") {
1006
+ canonicalUserKey = entry.message.userMessageUuid
1007
+ ? `user:${entry.message.userMessageUuid}`
1008
+ : null;
1009
+ continue;
1010
+ }
1011
+ if (entry.message.type !== "assistant" || !canonicalUserKey)
1012
+ continue;
1013
+ const contents = canonicalAssistantContentsByUser.get(canonicalUserKey);
1014
+ const contentKey = this.historyValueKey(entry.message.message.content);
1015
+ if (contents)
1016
+ contents.push(contentKey);
1017
+ else
1018
+ canonicalAssistantContentsByUser.set(canonicalUserKey, [contentKey]);
1019
+ }
1020
+ let pendingCanonicalAssistantContents = [];
1002
1021
  const retainedMessages = [];
1003
1022
  const retainedEntries = [];
1004
1023
  for (const entry of liveEntries) {
1005
1024
  if (!this.shouldRetainCodexLiveHistoryMessage(entry.message))
1006
1025
  continue;
1007
1026
  const keys = this.codexHistoryMessageIdentityKeys(entry.message);
1008
- if (keys.some((key) => canonicalKeys.has(key)))
1027
+ const matchesCanonical = keys.some((key) => canonicalKeys.has(key));
1028
+ if (entry.message.type === "user_input") {
1029
+ const userKey = entry.message.userMessageUuid
1030
+ ? `user:${entry.message.userMessageUuid}`
1031
+ : null;
1032
+ pendingCanonicalAssistantContents =
1033
+ matchesCanonical && userKey
1034
+ ? [...(canonicalAssistantContentsByUser.get(userKey) ?? [])]
1035
+ : [];
1036
+ }
1037
+ if (entry.message.type === "assistant") {
1038
+ const contentKey = this.historyValueKey(entry.message.message.content);
1039
+ const contentIndex = pendingCanonicalAssistantContents.indexOf(contentKey);
1040
+ if (matchesCanonical) {
1041
+ if (contentIndex !== -1) {
1042
+ pendingCanonicalAssistantContents.splice(contentIndex, 1);
1043
+ }
1044
+ continue;
1045
+ }
1046
+ const matchesCanonicalTurnAssistant = contentIndex !== -1;
1047
+ if (matchesCanonicalTurnAssistant) {
1048
+ pendingCanonicalAssistantContents.splice(contentIndex, 1);
1049
+ }
1050
+ if (matchesCanonicalTurnAssistant)
1051
+ continue;
1052
+ }
1053
+ if (matchesCanonical)
1009
1054
  continue;
1010
1055
  const seq = ++nextSeq;
1011
1056
  entry.message.historySeq = seq;