@widgetic/chat 0.1.9 → 0.1.10

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.
@@ -1331,7 +1331,20 @@
1331
1331
  if (localHasHead && !loadedHasHead) {
1332
1332
  // chatLog('[Chat] Keep local HEAD commit message — DB reload has no commit yet');
1333
1333
  } else {
1334
- chatStore.actions.setMessages(currentConversationId, loaded);
1334
+ // DB may lag behind the live session: the backend persists the codegen
1335
+ // summary asynchronously, so a reload fired shortly after generation can
1336
+ // still miss the newest commit. Only adopt the reload when it would not
1337
+ // regress the local HEAD to a different (older) commit.
1338
+ const localHeadSha = extractLatestLocalCommitSha(localMsgs);
1339
+ const loadedHeadSha = extractLatestLocalCommitSha(loaded);
1340
+ const wouldRegressHead =
1341
+ !!localHeadSha
1342
+ && (!loadedHeadSha || !loadedHeadSha.toLowerCase().startsWith(localHeadSha.slice(0, 7).toLowerCase()));
1343
+ if (wouldRegressHead) {
1344
+ // chatLog('[Chat] Keep local messages — DB reload would regress HEAD commit');
1345
+ } else {
1346
+ chatStore.actions.setMessages(currentConversationId, loaded);
1347
+ }
1335
1348
  }
1336
1349
  }
1337
1350
  markWidgetHeadAtLatestCommit();
@@ -1341,6 +1354,16 @@
1341
1354
  }
1342
1355
  }
1343
1356
 
1357
+ /** Newest commit SHA present in a message list (local session or DB reload). */
1358
+ function extractLatestLocalCommitSha(msgs: Array<{ messageContent?: string | null }> | null | undefined): string | null {
1359
+ if (!msgs) return null;
1360
+ for (let i = msgs.length - 1; i >= 0; i--) {
1361
+ const sha = extractCommitShaFromContent(msgs[i]?.messageContent || '');
1362
+ if (sha) return sha;
1363
+ }
1364
+ return null;
1365
+ }
1366
+
1344
1367
  function clearStalePreviewBuildFailures() {
1345
1368
  if (!currentConversationId) return;
1346
1369
  const msgs = getCurrentMessages(currentConversationId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/chat",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",