@widgetic/chat 0.1.29 → 0.1.31

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.
@@ -1609,6 +1609,25 @@
1609
1609
  // chatLog('[Chat] Patched last user message attachments:', mapped.length);
1610
1610
  }
1611
1611
 
1612
+ /**
1613
+ * A reload replaces the thread with the database rows. The property-edit
1614
+ * card is attached in memory on the assistant sentence; if that write did
1615
+ * not store the card, keep the one the page is already showing.
1616
+ */
1617
+ function keepLocalDesignCards(loaded: any[], localMsgs: any[]): any[] {
1618
+ return loaded.map((row) => {
1619
+ if (row?.designControls) return row;
1620
+ const text = String(row?.messageContent || '').trim();
1621
+ if (!text) return row;
1622
+ const twin = localMsgs.find((local) =>
1623
+ local?.designControls
1624
+ && local.messageType === row.messageType
1625
+ && String(local.messageContent || '').trim() === text
1626
+ );
1627
+ return twin ? { ...row, designControls: twin.designControls } : row;
1628
+ });
1629
+ }
1630
+
1612
1631
  /** Reload messages from backend and re-mark widget HEAD (picks up server-persisted summaries). */
1613
1632
  async function reloadConversationMessages() {
1614
1633
  if (!currentConversationId || !onLoadMessages) return;
@@ -1634,7 +1653,10 @@
1634
1653
  // chatLog('[Chat] Keep local messages — DB reload would regress HEAD commit');
1635
1654
  } else {
1636
1655
  hasOlderMessages = messageListHasOlder(loaded);
1637
- chatStore.actions.setMessages(currentConversationId, loaded);
1656
+ chatStore.actions.setMessages(
1657
+ currentConversationId,
1658
+ keepLocalDesignCards(loaded, localMsgs),
1659
+ );
1638
1660
  }
1639
1661
  }
1640
1662
  }
@@ -115,11 +115,19 @@
115
115
  onRequestOlderMessages,
116
116
  }: Props = $props();
117
117
 
118
+ /** The property-edit sentence used to be stored with markdown the bubble does not render. */
119
+ function readablePropertyEditLine(content: string): string {
120
+ return content.replace(
121
+ /^Updated \*\*(.+?)\*\* \(`[^`]+`\) to `([^`]*)`\.$/,
122
+ 'Updated $1 to $2.',
123
+ );
124
+ }
125
+
118
126
  /** What a visitor reads for stored assistant/system lines; matching still uses the English stored text. */
119
127
  function visibleMessageContent(content: string): string {
120
- const withoutContractNote = showGenerationSummaries
128
+ const withoutContractNote = readablePropertyEditLine(showGenerationSummaries
121
129
  ? content
122
- : content.replace(/\n*⚠️ Heads up:[\s\S]*$/i, '').trim();
130
+ : content.replace(/\n*⚠️ Heads up:[\s\S]*$/i, '').trim());
123
131
  if (!storedLineLabel) return withoutContractNote;
124
132
  try {
125
133
  return storedLineLabel(withoutContractNote);
@@ -746,9 +754,27 @@
746
754
 
747
755
  for (const message of messages) {
748
756
  if (message.messageType === 'user') {
757
+ // The property-edit shortcut used to save the same prompt again before
758
+ // any reply. Keep one user bubble.
759
+ const samePromptAgain =
760
+ current
761
+ && current.replies.length === 0
762
+ && (current.user?.messageContent || '').trim() === (message.messageContent || '').trim();
763
+ if (samePromptAgain) continue;
749
764
  if (current) turns.push(current);
750
765
  current = { user: message, replies: [] };
751
766
  } else if (current) {
767
+ const lastReply = current.replies[current.replies.length - 1];
768
+ const sameReplyAgain =
769
+ !!lastReply
770
+ && (lastReply.messageContent || '').trim() === (message.messageContent || '').trim();
771
+ if (sameReplyAgain) {
772
+ // The second copy is the one the page attached the card to.
773
+ if (!lastReply.designControls && message.designControls) {
774
+ current.replies[current.replies.length - 1] = message;
775
+ }
776
+ continue;
777
+ }
752
778
  current.replies.push(message);
753
779
  } else {
754
780
  turns.push({ user: null, replies: [message] });
@@ -887,6 +913,8 @@
887
913
  let keptGenerationText = $state('');
888
914
  let shownGenerationCount = $state(0);
889
915
  let thinkingShownCount = $state(0);
916
+ /** The thinking line stays after the preview, until the next send. */
917
+ let thinkingHold = $state(false);
890
918
  let generationWasRunning = false;
891
919
  // The first paint is shorter than the loaded page. Scrolling then, or treating
892
920
  // that short box as "the user is at the top", loads older pages and never
@@ -912,11 +940,14 @@
912
940
  keptGenerationText = '';
913
941
  shownGenerationCount = 0;
914
942
  thinkingShownCount = 0;
943
+ thinkingHold = true;
915
944
  }
916
945
  generationWasRunning = isGenerating;
917
946
  if (messages.length === 0 && !isGenerating) {
918
947
  keptGenerationText = '';
919
948
  shownGenerationCount = 0;
949
+ thinkingShownCount = 0;
950
+ thinkingHold = false;
920
951
  }
921
952
  });
922
953
 
@@ -941,7 +972,7 @@
941
972
  const thinkingLabel = $derived($t('chat.messages.thinking'));
942
973
 
943
974
  $effect(() => {
944
- if (!isGenerating || keptGenerationText) return;
975
+ if (!thinkingHold) return;
945
976
  const label = thinkingLabel;
946
977
  if (thinkingShownCount >= label.length) return;
947
978
  const timer = setInterval(() => {
@@ -1649,12 +1680,13 @@
1649
1680
  <p class="text-gray-500 text-xs">{$t('chat.messages.loadingHistory')}</p>
1650
1681
  </div>
1651
1682
  </div>
1652
- {:else if isGenerating && !shownGenerationText}
1683
+ {/if}
1684
+ {#if thinkingHold}
1653
1685
  <div class="loading-indicator-ct flex flex-col items-start gap-2 p-3">
1654
1686
  <div class="thinking-bubble relative inline-block whitespace-nowrap rounded-lg p-3 text-sm leading-relaxed shadow-sm"
1655
1687
  style="background-color: {MESSAGE_COLORS.ASSISTANT}; color: {MESSAGE_COLORS.ASSISTANT_TEXT}"
1656
1688
  >
1657
- <span class="thinking-sizer invisible" aria-hidden="true">{thinkingLabel}</span>
1689
+ <span class="thinking-sizer" aria-hidden="true">{thinkingLabel}</span>
1658
1690
  <span class="thinking-reveal absolute inset-0 flex items-center px-3">{shownThinkingLabel}</span>
1659
1691
  </div>
1660
1692
  </div>
@@ -1667,6 +1699,9 @@
1667
1699
  </div>
1668
1700
 
1669
1701
  <style>
1702
+ .thinking-sizer {
1703
+ visibility: hidden;
1704
+ }
1670
1705
  .thinking-reveal {
1671
1706
  background-image: linear-gradient(100deg, #1f2937 35%, #ffffff 50%, #1f2937 65%);
1672
1707
  background-size: 200% 100%;
@@ -58,7 +58,6 @@ export declare const CHAT_MESSAGES: {
58
58
  readonly 'chat.messages.restore': "Restore Checkpoint";
59
59
  readonly 'chat.messages.restoreTitle': "Restore widget code to this prompt's commit";
60
60
  readonly 'chat.messages.alreadyHead': "This checkpoint is already HEAD";
61
- readonly 'chat.messages.showSuggestions': "Show suggestions";
62
61
  /**
63
62
  * Versions are named "Version 4" between the page and the chat, and in the lines the chat saves ("Restored from Version
64
63
  * 4"): the chat reads the number out of those words. It says them again in the page's language with these three.
@@ -62,7 +62,6 @@ export const CHAT_MESSAGES = {
62
62
  'chat.messages.restore': 'Restore Checkpoint',
63
63
  'chat.messages.restoreTitle': 'Restore widget code to this prompt\'s commit',
64
64
  'chat.messages.alreadyHead': 'This checkpoint is already HEAD',
65
- 'chat.messages.showSuggestions': 'Show suggestions',
66
65
  /**
67
66
  * Versions are named "Version 4" between the page and the chat, and in the lines the chat saves ("Restored from Version
68
67
  * 4"): the chat reads the number out of those words. It says them again in the page's language with these three.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/chat",
3
- "version": "0.1.29",
3
+ "version": "0.1.31",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",