@widgetic/chat 0.1.30 → 0.1.32
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(
|
|
1656
|
+
chatStore.actions.setMessages(
|
|
1657
|
+
currentConversationId,
|
|
1658
|
+
keepLocalDesignCards(loaded, localMsgs),
|
|
1659
|
+
);
|
|
1638
1660
|
}
|
|
1639
1661
|
}
|
|
1640
1662
|
}
|
|
@@ -1751,7 +1773,7 @@
|
|
|
1751
1773
|
let lastGenerationOptionsHeight = 0;
|
|
1752
1774
|
let generationOptionsHeightReady = false;
|
|
1753
1775
|
|
|
1754
|
-
//
|
|
1776
|
+
// The generation options (language, libraries) sit in the footer. Grow the host by that height so
|
|
1755
1777
|
// the messages area stays put and the input moves down inside the scroller.
|
|
1756
1778
|
$effect(() => {
|
|
1757
1779
|
const el = generationOptionsEl;
|
|
@@ -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] });
|
|
@@ -883,10 +909,12 @@
|
|
|
883
909
|
// Local state
|
|
884
910
|
let messagesContainer: HTMLElement;
|
|
885
911
|
let autoScroll = $state(true);
|
|
886
|
-
/** Model text
|
|
912
|
+
/** Model text shown while code is streaming. Cleared when the generation finishes. */
|
|
887
913
|
let keptGenerationText = $state('');
|
|
888
914
|
let shownGenerationCount = $state(0);
|
|
889
915
|
let thinkingShownCount = $state(0);
|
|
916
|
+
/** The thinking line is up only while a generation is running. */
|
|
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,20 @@
|
|
|
912
940
|
keptGenerationText = '';
|
|
913
941
|
shownGenerationCount = 0;
|
|
914
942
|
thinkingShownCount = 0;
|
|
943
|
+
thinkingHold = true;
|
|
944
|
+
}
|
|
945
|
+
if (!isGenerating && generationWasRunning) {
|
|
946
|
+
keptGenerationText = '';
|
|
947
|
+
shownGenerationCount = 0;
|
|
948
|
+
thinkingShownCount = 0;
|
|
949
|
+
thinkingHold = false;
|
|
915
950
|
}
|
|
916
951
|
generationWasRunning = isGenerating;
|
|
917
952
|
if (messages.length === 0 && !isGenerating) {
|
|
918
953
|
keptGenerationText = '';
|
|
919
954
|
shownGenerationCount = 0;
|
|
955
|
+
thinkingShownCount = 0;
|
|
956
|
+
thinkingHold = false;
|
|
920
957
|
}
|
|
921
958
|
});
|
|
922
959
|
|
|
@@ -941,7 +978,7 @@
|
|
|
941
978
|
const thinkingLabel = $derived($t('chat.messages.thinking'));
|
|
942
979
|
|
|
943
980
|
$effect(() => {
|
|
944
|
-
if (!
|
|
981
|
+
if (!thinkingHold) return;
|
|
945
982
|
const label = thinkingLabel;
|
|
946
983
|
if (thinkingShownCount >= label.length) return;
|
|
947
984
|
const timer = setInterval(() => {
|
|
@@ -1528,7 +1565,7 @@
|
|
|
1528
1565
|
{/if}
|
|
1529
1566
|
</div>
|
|
1530
1567
|
{#if !turn.user?.id?.startsWith('version-fork-') && !isLoading && ((commitReply && (canRestoreToMessage(commitReply) || isHeadCommitReply(commitReply))) || canRestoreFailedLastTurn(turn))}
|
|
1531
|
-
{@const restoreIsCurrentHead = !!(commitReply && isHeadCommitReply(commitReply))}
|
|
1568
|
+
{@const restoreIsCurrentHead = !!(commitReply && isHeadCommitReply(commitReply) && versionNumberFromLabel(getTurnVersionLabel(turn)) !== 1)}
|
|
1532
1569
|
<button
|
|
1533
1570
|
class="restore-checkpoint-btn shrink-0"
|
|
1534
1571
|
disabled={restoreIsCurrentHead}
|
|
@@ -1649,12 +1686,13 @@
|
|
|
1649
1686
|
<p class="text-gray-500 text-xs">{$t('chat.messages.loadingHistory')}</p>
|
|
1650
1687
|
</div>
|
|
1651
1688
|
</div>
|
|
1652
|
-
{
|
|
1689
|
+
{/if}
|
|
1690
|
+
{#if thinkingHold}
|
|
1653
1691
|
<div class="loading-indicator-ct flex flex-col items-start gap-2 p-3">
|
|
1654
1692
|
<div class="thinking-bubble relative inline-block whitespace-nowrap rounded-lg p-3 text-sm leading-relaxed shadow-sm"
|
|
1655
1693
|
style="background-color: {MESSAGE_COLORS.ASSISTANT}; color: {MESSAGE_COLORS.ASSISTANT_TEXT}"
|
|
1656
1694
|
>
|
|
1657
|
-
<span class="thinking-sizer
|
|
1695
|
+
<span class="thinking-sizer" aria-hidden="true">{thinkingLabel}</span>
|
|
1658
1696
|
<span class="thinking-reveal absolute inset-0 flex items-center px-3">{shownThinkingLabel}</span>
|
|
1659
1697
|
</div>
|
|
1660
1698
|
</div>
|
|
@@ -1667,6 +1705,9 @@
|
|
|
1667
1705
|
</div>
|
|
1668
1706
|
|
|
1669
1707
|
<style>
|
|
1708
|
+
.thinking-sizer {
|
|
1709
|
+
visibility: hidden;
|
|
1710
|
+
}
|
|
1670
1711
|
.thinking-reveal {
|
|
1671
1712
|
background-image: linear-gradient(100deg, #1f2937 35%, #ffffff 50%, #1f2937 65%);
|
|
1672
1713
|
background-size: 200% 100%;
|