@ccpocket/bridge 1.67.2 → 1.67.4

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;
@@ -1114,6 +1159,7 @@ export class BridgeWebSocketServer {
1114
1159
  });
1115
1160
  this.sendCodexCurrentSettings(ws, sessionId, session);
1116
1161
  this.sendCodexQueueState(ws, sessionId, session);
1162
+ this.sendCodexGoalState(ws, sessionId, session);
1117
1163
  if (options.includeCachedCommands) {
1118
1164
  this.sendCachedCommands(ws, sessionId, session);
1119
1165
  }
@@ -1144,6 +1190,7 @@ export class BridgeWebSocketServer {
1144
1190
  sessionId,
1145
1191
  });
1146
1192
  this.sendCodexQueueState(ws, sessionId, session);
1193
+ this.sendCodexGoalState(ws, sessionId, session);
1147
1194
  this.sendCachedCommands(ws, sessionId, session);
1148
1195
  return true;
1149
1196
  }
@@ -2991,6 +3038,7 @@ export class BridgeWebSocketServer {
2991
3038
  });
2992
3039
  if (session.provider === "codex") {
2993
3040
  this.sendCodexQueueState(ws, msg.sessionId, session);
3041
+ this.sendCodexGoalState(ws, msg.sessionId, session);
2994
3042
  }
2995
3043
  this.sendCachedCommands(ws, msg.sessionId, session);
2996
3044
  }
@@ -3028,6 +3076,7 @@ export class BridgeWebSocketServer {
3028
3076
  });
3029
3077
  this.sendCodexCurrentSettings(ws, msg.sessionId, session);
3030
3078
  this.sendCodexQueueState(ws, msg.sessionId, session);
3079
+ this.sendCodexGoalState(ws, msg.sessionId, session);
3031
3080
  break;
3032
3081
  }
3033
3082
  if (session) {
@@ -5653,6 +5702,15 @@ export class BridgeWebSocketServer {
5653
5702
  : [],
5654
5703
  });
5655
5704
  }
5705
+ sendCodexGoalState(ws, sessionId, session) {
5706
+ if (session.codexGoal === undefined)
5707
+ return;
5708
+ this.send(ws, {
5709
+ type: "goal_state",
5710
+ sessionId,
5711
+ goal: session.codexGoal,
5712
+ });
5713
+ }
5656
5714
  sendCachedCommands(ws, sessionId, session) {
5657
5715
  // Restore command metadata when the original init/supported_commands event
5658
5716
  // has fallen out of the bounded in-memory history.