@widgetic/chat 0.1.27 → 0.1.28
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.
|
@@ -1488,7 +1488,7 @@
|
|
|
1488
1488
|
|
|
1489
1489
|
// Terminal codegen status lines: the normal completion and the semantic-cache
|
|
1490
1490
|
// "already done" affordance. Both are turn-deduped status bubbles.
|
|
1491
|
-
const CODEGEN_STATUS_MESSAGE_REGEX = /^(Code generation completed|Already done)/i;
|
|
1491
|
+
const CODEGEN_STATUS_MESSAGE_REGEX = /^(Code generation completed|Already done|Generation complete \(100%\))/i;
|
|
1492
1492
|
|
|
1493
1493
|
function isCodegenStatusMessage(content?: string | null): boolean {
|
|
1494
1494
|
return CODEGEN_STATUS_MESSAGE_REGEX.test((content || '').trim());
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
import { chatLog } from '../utils/logger.js';
|
|
6
6
|
import { AttachmentDisplay, SuggestionButtons } from './index.js';
|
|
7
7
|
import CodeBlock from './CodeBlock.svelte';
|
|
8
|
-
import LoadingIndicator from './LoadingIndicator.svelte';
|
|
9
8
|
import { onDestroy, onMount, tick } from 'svelte';
|
|
10
9
|
import type { Snippet } from 'svelte';
|
|
11
10
|
import { useChatLanguage } from '../i18n/language.js';
|
|
@@ -118,12 +117,15 @@
|
|
|
118
117
|
|
|
119
118
|
/** What a visitor reads for stored assistant/system lines; matching still uses the English stored text. */
|
|
120
119
|
function visibleMessageContent(content: string): string {
|
|
121
|
-
|
|
120
|
+
const withoutContractNote = showGenerationSummaries
|
|
121
|
+
? content
|
|
122
|
+
: content.replace(/\n*⚠️ Heads up:[\s\S]*$/i, '').trim();
|
|
123
|
+
if (!storedLineLabel) return withoutContractNote;
|
|
122
124
|
try {
|
|
123
|
-
return storedLineLabel(
|
|
125
|
+
return storedLineLabel(withoutContractNote);
|
|
124
126
|
} catch (error) {
|
|
125
127
|
console.warn('[Chat] storedLineLabel failed:', error);
|
|
126
|
-
return
|
|
128
|
+
return withoutContractNote;
|
|
127
129
|
}
|
|
128
130
|
}
|
|
129
131
|
|
|
@@ -703,6 +705,7 @@
|
|
|
703
705
|
const trimmed = (content || '').trim();
|
|
704
706
|
return (
|
|
705
707
|
/^Code generation completed/i.test(trimmed) ||
|
|
708
|
+
/^Generation complete \(100%\)/i.test(trimmed) ||
|
|
706
709
|
/^Code saved/i.test(trimmed) ||
|
|
707
710
|
/^Compile fix applied/i.test(trimmed) ||
|
|
708
711
|
/^Preview recompiled/i.test(trimmed) ||
|
|
@@ -712,6 +715,8 @@
|
|
|
712
715
|
|
|
713
716
|
/** Whether this assistant bubble should render (vs commit chrome on user message). */
|
|
714
717
|
function shouldShowAssistantReply(reply: ChatMessage): boolean {
|
|
718
|
+
const trimmedReply = (reply.messageContent || '').trim();
|
|
719
|
+
if (!showGenerationSummaries && /^⚠️ Heads up:/i.test(trimmedReply)) return false;
|
|
715
720
|
if (isCodegenFailure(reply)) return true;
|
|
716
721
|
if (showGenerationSummaries) return true;
|
|
717
722
|
if (isCodegenProgressBubble(reply.messageContent)) return false;
|
|
@@ -877,18 +882,78 @@
|
|
|
877
882
|
|
|
878
883
|
// Local state
|
|
879
884
|
let messagesContainer: HTMLElement;
|
|
880
|
-
let showSuggestionsInline = $state(false);
|
|
881
885
|
let autoScroll = $state(true);
|
|
886
|
+
/** Model text kept after the preview is up, so thinking and code stay in the thread. */
|
|
887
|
+
let keptGenerationText = $state('');
|
|
888
|
+
let shownGenerationCount = $state(0);
|
|
889
|
+
let thinkingShownCount = $state(0);
|
|
890
|
+
let generationWasRunning = false;
|
|
882
891
|
// The first paint is shorter than the loaded page. Scrolling then, or treating
|
|
883
892
|
// that short box as "the user is at the top", loads older pages and never
|
|
884
893
|
// lands on the newest message. Pin once, after this load has finished.
|
|
885
894
|
let initialBottomPinned = $state(false);
|
|
886
895
|
|
|
887
|
-
|
|
888
|
-
|
|
896
|
+
function mergeGenerationStream(previous: string, incoming: string): string {
|
|
897
|
+
if (!incoming) return previous;
|
|
898
|
+
if (!previous || incoming.startsWith(previous)) return incoming;
|
|
899
|
+
if (previous.includes(incoming)) return previous;
|
|
900
|
+
const maxOverlap = Math.min(previous.length, incoming.length);
|
|
901
|
+
for (let size = maxOverlap; size > 20; size -= 1) {
|
|
902
|
+
if (previous.slice(-size) === incoming.slice(0, size)) {
|
|
903
|
+
return previous + incoming.slice(size);
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
return previous + '\n' + incoming;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
// A new send starts a fresh transcript. An empty thread drops the previous one.
|
|
910
|
+
$effect(() => {
|
|
911
|
+
if (isGenerating && !generationWasRunning) {
|
|
912
|
+
keptGenerationText = '';
|
|
913
|
+
shownGenerationCount = 0;
|
|
914
|
+
thinkingShownCount = 0;
|
|
915
|
+
}
|
|
916
|
+
generationWasRunning = isGenerating;
|
|
917
|
+
if (messages.length === 0 && !isGenerating) {
|
|
918
|
+
keptGenerationText = '';
|
|
919
|
+
shownGenerationCount = 0;
|
|
920
|
+
}
|
|
921
|
+
});
|
|
922
|
+
|
|
889
923
|
$effect(() => {
|
|
890
|
-
|
|
924
|
+
const incoming = generationStream;
|
|
925
|
+
if (!incoming) return;
|
|
926
|
+
const merged = mergeGenerationStream(keptGenerationText, incoming);
|
|
927
|
+
if (merged !== keptGenerationText) keptGenerationText = merged;
|
|
891
928
|
});
|
|
929
|
+
|
|
930
|
+
// Reveal from the first character already on screen, then catch up to new tokens.
|
|
931
|
+
$effect(() => {
|
|
932
|
+
const target = keptGenerationText.length;
|
|
933
|
+
if (shownGenerationCount >= target) return;
|
|
934
|
+
const timer = setInterval(() => {
|
|
935
|
+
shownGenerationCount = Math.min(keptGenerationText.length, shownGenerationCount + 8);
|
|
936
|
+
if (shownGenerationCount >= keptGenerationText.length) clearInterval(timer);
|
|
937
|
+
}, 20);
|
|
938
|
+
return () => clearInterval(timer);
|
|
939
|
+
});
|
|
940
|
+
|
|
941
|
+
const thinkingLabel = $derived($t('chat.messages.thinking'));
|
|
942
|
+
|
|
943
|
+
$effect(() => {
|
|
944
|
+
if (!isGenerating || keptGenerationText) return;
|
|
945
|
+
const label = thinkingLabel;
|
|
946
|
+
if (thinkingShownCount >= label.length) return;
|
|
947
|
+
const timer = setInterval(() => {
|
|
948
|
+
thinkingShownCount = Math.min(label.length, thinkingShownCount + 1);
|
|
949
|
+
if (thinkingShownCount >= label.length) clearInterval(timer);
|
|
950
|
+
}, 28);
|
|
951
|
+
return () => clearInterval(timer);
|
|
952
|
+
});
|
|
953
|
+
|
|
954
|
+
const shownThinkingLabel = $derived(thinkingLabel.slice(0, thinkingShownCount));
|
|
955
|
+
|
|
956
|
+
const shownGenerationText = $derived(keptGenerationText.slice(0, shownGenerationCount));
|
|
892
957
|
/**
|
|
893
958
|
* Opening on a small screen often resizes the container (parent panel layout)
|
|
894
959
|
* AFTER mount, which resets scroll to the top and clips the input below the
|
|
@@ -931,7 +996,7 @@
|
|
|
931
996
|
}
|
|
932
997
|
const pinToBottom = shouldPinChatToBottom();
|
|
933
998
|
const messageCount = visibleMessages.length;
|
|
934
|
-
const streamLength =
|
|
999
|
+
const streamLength = shownGenerationText.length;
|
|
935
1000
|
if (!initialBottomPinned && messagesContainer && messageCount > 0 && !pendingOlderScroll) {
|
|
936
1001
|
void tick().then(() => settleMessagesToEnd());
|
|
937
1002
|
}
|
|
@@ -1576,27 +1641,6 @@
|
|
|
1576
1641
|
</div>
|
|
1577
1642
|
{/each}
|
|
1578
1643
|
|
|
1579
|
-
<!-- Show suggestions toggle (when there are messages) -->
|
|
1580
|
-
{#if messages.length > 0 && !isLoading && !isGenerating}
|
|
1581
|
-
<div class="suggestions-toggle-ct flex justify-center py-2">
|
|
1582
|
-
{#if showSuggestionsInline}
|
|
1583
|
-
<SuggestionButtons
|
|
1584
|
-
{context}
|
|
1585
|
-
visible={true}
|
|
1586
|
-
onHide={() => { showSuggestionsInline = false; }}
|
|
1587
|
-
on:suggestionSelected={(e) => { showSuggestionsInline = false; handleSuggestionSelected(e); }}
|
|
1588
|
-
/>
|
|
1589
|
-
{:else}
|
|
1590
|
-
<button
|
|
1591
|
-
class="suggestions-toggle-btn text-xs text-gray-400 hover:text-gray-600 px-3 py-1.5 rounded-full border border-gray-200 hover:border-gray-300 bg-white hover:bg-gray-50 transition-colors cursor-pointer"
|
|
1592
|
-
onclick={() => { showSuggestionsInline = true; }}
|
|
1593
|
-
>
|
|
1594
|
-
{$t('chat.messages.showSuggestions')}
|
|
1595
|
-
</button>
|
|
1596
|
-
{/if}
|
|
1597
|
-
</div>
|
|
1598
|
-
{/if}
|
|
1599
|
-
|
|
1600
1644
|
<!-- Loading indicator -->
|
|
1601
1645
|
{#if messages.length === 0 && isLoading}
|
|
1602
1646
|
<div class="loading-history-ct flex flex-1 items-center justify-center p-8">
|
|
@@ -1605,26 +1649,36 @@
|
|
|
1605
1649
|
<p class="text-gray-500 text-xs">{$t('chat.messages.loadingHistory')}</p>
|
|
1606
1650
|
</div>
|
|
1607
1651
|
</div>
|
|
1608
|
-
{:else if
|
|
1652
|
+
{:else if isGenerating && !shownGenerationText}
|
|
1609
1653
|
<div class="loading-indicator-ct flex flex-col items-start gap-2 p-3">
|
|
1610
|
-
<div class="rounded-lg
|
|
1654
|
+
<div class="thinking-bubble relative inline-block whitespace-nowrap rounded-lg p-3 text-sm leading-relaxed shadow-sm"
|
|
1611
1655
|
style="background-color: {MESSAGE_COLORS.ASSISTANT}; color: {MESSAGE_COLORS.ASSISTANT_TEXT}"
|
|
1612
1656
|
>
|
|
1613
|
-
<
|
|
1614
|
-
|
|
1615
|
-
text={$t('chat.messages.thinking')}
|
|
1616
|
-
color="secondary"
|
|
1617
|
-
size="md"
|
|
1618
|
-
/>
|
|
1657
|
+
<span class="thinking-sizer invisible" aria-hidden="true">{thinkingLabel}</span>
|
|
1658
|
+
<span class="thinking-reveal absolute inset-0 flex items-center px-3">{shownThinkingLabel}</span>
|
|
1619
1659
|
</div>
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1660
|
+
</div>
|
|
1661
|
+
{/if}
|
|
1662
|
+
{#if shownGenerationText}
|
|
1663
|
+
<div class="generation-stream-ct flex flex-col items-start gap-2 px-3 pb-3">
|
|
1664
|
+
<pre class="generation-stream m-0 max-h-40 w-full overflow-auto whitespace-pre-wrap break-words rounded-lg bg-gray-900 p-3 font-mono text-[11px] leading-relaxed text-gray-100">{shownGenerationText}</pre>
|
|
1623
1665
|
</div>
|
|
1624
1666
|
{/if}
|
|
1625
1667
|
</div>
|
|
1626
1668
|
|
|
1627
1669
|
<style>
|
|
1670
|
+
.thinking-reveal {
|
|
1671
|
+
background-image: linear-gradient(100deg, #1f2937 35%, #ffffff 50%, #1f2937 65%);
|
|
1672
|
+
background-size: 200% 100%;
|
|
1673
|
+
-webkit-background-clip: text;
|
|
1674
|
+
background-clip: text;
|
|
1675
|
+
color: transparent;
|
|
1676
|
+
animation: thinking-shine 1.6s linear infinite;
|
|
1677
|
+
}
|
|
1678
|
+
@keyframes thinking-shine {
|
|
1679
|
+
0% { background-position: 100% 0; }
|
|
1680
|
+
100% { background-position: -100% 0; }
|
|
1681
|
+
}
|
|
1628
1682
|
.generation-stream {
|
|
1629
1683
|
scrollbar-width: thin;
|
|
1630
1684
|
scrollbar-color: rgba(255, 255, 255, 0.35) transparent;
|
package/dist/i18n/messages.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export declare const CHAT_MESSAGES: {
|
|
|
41
41
|
readonly 'chat.messages.startHint': "Ask a question about your {type} to get started.";
|
|
42
42
|
readonly 'chat.messages.loadingHistory': "Loading chat history...";
|
|
43
43
|
/** Said while the assistant works on an answer. */
|
|
44
|
-
readonly 'chat.messages.thinking': "Assistant is thinking
|
|
44
|
+
readonly 'chat.messages.thinking': "Assistant is thinking";
|
|
45
45
|
/** The mark on the turn of the version that is open now, and the line that explains it. */
|
|
46
46
|
readonly 'chat.messages.viewing': "You are here";
|
|
47
47
|
readonly 'chat.messages.viewingTitle': "This is the version you are looking at";
|
|
@@ -75,7 +75,7 @@ export declare const CHAT_MESSAGES: {
|
|
|
75
75
|
readonly 'chat.suggestions.hide': "Hide suggestions";
|
|
76
76
|
/** The ideas for a widget: tapping one sends it as the person's own message. */
|
|
77
77
|
readonly 'chat.suggestions.frame.generateCode': "Generate code from this design";
|
|
78
|
-
readonly 'chat.suggestions.frame.improveLayout': "
|
|
78
|
+
readonly 'chat.suggestions.frame.improveLayout': "Improve this layout";
|
|
79
79
|
readonly 'chat.suggestions.frame.addInteractivity': "Add interactive functionality";
|
|
80
80
|
readonly 'chat.suggestions.frame.makeResponsive': "Make this responsive for mobile";
|
|
81
81
|
readonly 'chat.suggestions.frame.addAnimations': "Add animations and transitions";
|
package/dist/i18n/messages.js
CHANGED
|
@@ -45,7 +45,7 @@ export const CHAT_MESSAGES = {
|
|
|
45
45
|
'chat.messages.startHint': 'Ask a question about your {type} to get started.',
|
|
46
46
|
'chat.messages.loadingHistory': 'Loading chat history...',
|
|
47
47
|
/** Said while the assistant works on an answer. */
|
|
48
|
-
'chat.messages.thinking': 'Assistant is thinking
|
|
48
|
+
'chat.messages.thinking': 'Assistant is thinking',
|
|
49
49
|
/** The mark on the turn of the version that is open now, and the line that explains it. */
|
|
50
50
|
'chat.messages.viewing': 'You are here',
|
|
51
51
|
'chat.messages.viewingTitle': 'This is the version you are looking at',
|
|
@@ -80,7 +80,7 @@ export const CHAT_MESSAGES = {
|
|
|
80
80
|
'chat.suggestions.hide': 'Hide suggestions',
|
|
81
81
|
/** The ideas for a widget: tapping one sends it as the person's own message. */
|
|
82
82
|
'chat.suggestions.frame.generateCode': 'Generate code from this design',
|
|
83
|
-
'chat.suggestions.frame.improveLayout': '
|
|
83
|
+
'chat.suggestions.frame.improveLayout': 'Improve this layout',
|
|
84
84
|
'chat.suggestions.frame.addInteractivity': 'Add interactive functionality',
|
|
85
85
|
'chat.suggestions.frame.makeResponsive': 'Make this responsive for mobile',
|
|
86
86
|
'chat.suggestions.frame.addAnimations': 'Add animations and transitions',
|