@widgetic/chat 0.1.26 → 0.1.27
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.
|
@@ -143,6 +143,8 @@
|
|
|
143
143
|
viewingVersion?: number | null;
|
|
144
144
|
/** Host is running widget codegen — send button becomes stop. */
|
|
145
145
|
isGenerating?: boolean;
|
|
146
|
+
/** Tail of the model stream while codegen is in flight. */
|
|
147
|
+
generationStream?: string;
|
|
146
148
|
onStopGeneration?: () => void;
|
|
147
149
|
/**
|
|
148
150
|
* Renders the inline design-control card attached to an assistant reply
|
|
@@ -216,7 +218,7 @@
|
|
|
216
218
|
updateLastUserMessageAttachments: (attachments: Array<{ id?: string; url: string; file_type?: string; file_name?: string | null }>) => void;
|
|
217
219
|
}
|
|
218
220
|
|
|
219
|
-
let { context, config = {}, class: className = '', locale = null, messages: languageMessages = null, dir = undefined, style = '', isCompleted = false, onStatsUpdate, onChatReady, onCompletionToggle, onSendMessage, onLoadConversations, onLoadMessages, onCreateConversation, onSaveMessage, onRestoreCheckpointBackend, onTakeScreenshot, onConversationChange, onDraftChange, onRetryMessage, onUpgradePlans, onUploadChatFile, showHeader = true, headerTitle = '', showDescriptionHeader = true, showLogs = true, resizeExpandsContainer = false, onMessagesResize, onMessagesDrag, onMessagesDragEnd, onLoadOlderMessages, widgetHeadCommitSha = null, versionLabelByCommitSha = {}, versionLabelByPrompt = {}, versionTimeline = [], viewingVersion = null, isGenerating = false, onStopGeneration, renderDesignControls, actionBarExtras, completeReplacement, replaceComplete = false, showSelector = false, isSelectorActive = false, selectedElements = [], onToggleSelector, onRemoveSelectedElement, onClearSelectedElements, composerExtras, storedLineLabel }: Props = $props();
|
|
221
|
+
let { context, config = {}, class: className = '', locale = null, messages: languageMessages = null, dir = undefined, style = '', isCompleted = false, onStatsUpdate, onChatReady, onCompletionToggle, onSendMessage, onLoadConversations, onLoadMessages, onCreateConversation, onSaveMessage, onRestoreCheckpointBackend, onTakeScreenshot, onConversationChange, onDraftChange, onRetryMessage, onUpgradePlans, onUploadChatFile, showHeader = true, headerTitle = '', showDescriptionHeader = true, showLogs = true, resizeExpandsContainer = false, onMessagesResize, onMessagesDrag, onMessagesDragEnd, onLoadOlderMessages, widgetHeadCommitSha = null, versionLabelByCommitSha = {}, versionLabelByPrompt = {}, versionTimeline = [], viewingVersion = null, isGenerating = false, generationStream = '', onStopGeneration, renderDesignControls, actionBarExtras, completeReplacement, replaceComplete = false, showSelector = false, isSelectorActive = false, selectedElements = [], onToggleSelector, onRemoveSelectedElement, onClearSelectedElements, composerExtras, storedLineLabel }: Props = $props();
|
|
220
222
|
|
|
221
223
|
// The words of everything inside the chat, in the language the page chose. The page can change the language while the
|
|
222
224
|
// chat is open: the settings are read again whenever they change (and setting the same language again does nothing).
|
|
@@ -1247,7 +1249,24 @@
|
|
|
1247
1249
|
const rollback = result?.gitRollback || result?.git_rollback || result?.data?.gitRollback || result?.data?.git_rollback;
|
|
1248
1250
|
const newSha = String(rollback?.commitId || rollback?.commit_id || '').trim();
|
|
1249
1251
|
if (rollback?.success && newSha && promptCopy) {
|
|
1250
|
-
|
|
1252
|
+
const attachmentSource = (checkpointUser?.attachments || []).some((attachment: { url?: string }) => !!attachment?.url)
|
|
1253
|
+
? checkpointUser
|
|
1254
|
+
: currentMessages.find((message: any) =>
|
|
1255
|
+
message?.messageType === 'user'
|
|
1256
|
+
&& String(message.messageContent || '').trim() === promptCopy
|
|
1257
|
+
&& (message.attachments || []).some((attachment: { url?: string }) => !!attachment?.url)
|
|
1258
|
+
);
|
|
1259
|
+
const restoredAttachments = (attachmentSource?.attachments || [])
|
|
1260
|
+
.filter((attachment: { url?: string }) => !!attachment?.url)
|
|
1261
|
+
.map((attachment: { id?: string; url: string; file_type?: string; fileType?: string; file_name?: string; fileName?: string; file_size?: number; fileSize?: number }) => ({
|
|
1262
|
+
id: String(attachment.id || attachment.url),
|
|
1263
|
+
url: attachment.url,
|
|
1264
|
+
file_type: attachment.file_type || attachment.fileType || 'image/png',
|
|
1265
|
+
file_name: attachment.file_name || attachment.fileName || 'design-screenshot.png',
|
|
1266
|
+
file_size: attachment.file_size ?? attachment.fileSize,
|
|
1267
|
+
}));
|
|
1268
|
+
console.log('[Chat] Restore echo attachments', restoredAttachments.length);
|
|
1269
|
+
addUserMessage(promptCopy, restoredAttachments.length ? restoredAttachments : undefined);
|
|
1251
1270
|
addAssistantMessage(`Restored from ${sourceLabel}\n\nCommit: ${newSha.slice(0, 8)}`);
|
|
1252
1271
|
}
|
|
1253
1272
|
} catch (backendError) {
|
|
@@ -1862,6 +1881,7 @@
|
|
|
1862
1881
|
onRequestOlderMessages={() => loadOlderMessages()}
|
|
1863
1882
|
showCommitMeta={showLogs}
|
|
1864
1883
|
isGenerating={isGenerating || isLoading}
|
|
1884
|
+
generationStream={isGenerating ? generationStream : ''}
|
|
1865
1885
|
onSuggestionSelected={handleSuggestionSelected}
|
|
1866
1886
|
onRestoreCheckpoint={handleRestoreCheckpoint}
|
|
1867
1887
|
onRetryMessage={handleRetryMessage}
|
|
@@ -186,6 +186,8 @@ interface Props {
|
|
|
186
186
|
viewingVersion?: number | null;
|
|
187
187
|
/** Host is running widget codegen — send button becomes stop. */
|
|
188
188
|
isGenerating?: boolean;
|
|
189
|
+
/** Tail of the model stream while codegen is in flight. */
|
|
190
|
+
generationStream?: string;
|
|
189
191
|
onStopGeneration?: () => void;
|
|
190
192
|
/**
|
|
191
193
|
* Renders the inline design-control card attached to an assistant reply
|
|
@@ -63,6 +63,8 @@
|
|
|
63
63
|
showCommitMeta?: boolean;
|
|
64
64
|
/** True while codegen / send is in flight — suppresses premature Retry. */
|
|
65
65
|
isGenerating?: boolean;
|
|
66
|
+
/** Tail of the model stream for the generation in flight. Empty when it is only thinking. */
|
|
67
|
+
generationStream?: string;
|
|
66
68
|
onSuggestionSelected?: (suggestion: string) => void;
|
|
67
69
|
onRestoreCheckpoint?: (messageId: string, messageIndex: number) => void;
|
|
68
70
|
onRetryMessage?: (content: string) => void;
|
|
@@ -102,6 +104,7 @@
|
|
|
102
104
|
viewingVersion = null,
|
|
103
105
|
showCommitMeta = true,
|
|
104
106
|
isGenerating = false,
|
|
107
|
+
generationStream = '',
|
|
105
108
|
onSuggestionSelected,
|
|
106
109
|
onRestoreCheckpoint,
|
|
107
110
|
onRetryMessage,
|
|
@@ -340,8 +343,15 @@
|
|
|
340
343
|
return expanded;
|
|
341
344
|
}
|
|
342
345
|
|
|
346
|
+
function turnIsRestoreEcho(turn: ChatTurn): boolean {
|
|
347
|
+
return turn.replies.some((reply) => isRestoreForkContent(reply.messageContent));
|
|
348
|
+
}
|
|
349
|
+
|
|
343
350
|
function visibleUserAttachments(turn: ChatTurn, turnIndex: number) {
|
|
344
351
|
const attachments = turn.user?.attachments || [];
|
|
352
|
+
// Restore adds a copy of the prompt. That copy should keep the sketch image
|
|
353
|
+
// the original turn showed, even though it is not the first message.
|
|
354
|
+
if (turnIsRestoreEcho(turn)) return attachments;
|
|
345
355
|
const hasEarlierUser = chatTurns.slice(0, turnIndex).some((candidate) => candidate.user);
|
|
346
356
|
if (!hasEarlierUser) return attachments;
|
|
347
357
|
// The opening sketch stays on the first turn. Later prompts must not
|
|
@@ -774,6 +784,9 @@
|
|
|
774
784
|
}
|
|
775
785
|
|
|
776
786
|
function shouldPinChatToBottom(): boolean {
|
|
787
|
+
// A live generation grows under the list. Stay on that tail even when an
|
|
788
|
+
// older version is the one marked "you are here".
|
|
789
|
+
if (isGenerating) return true;
|
|
777
790
|
if (viewingVersion != null) {
|
|
778
791
|
const hereIndex = viewingTurnIndex();
|
|
779
792
|
if (hereIndex < 0 || hereIndex < chatTurns.length - 1) return false;
|
|
@@ -781,6 +794,11 @@
|
|
|
781
794
|
return autoScroll;
|
|
782
795
|
}
|
|
783
796
|
|
|
797
|
+
function scrollGenerationTail(): void {
|
|
798
|
+
const tail = messagesContainer?.querySelector('.generation-stream');
|
|
799
|
+
if (tail) tail.scrollTop = tail.scrollHeight;
|
|
800
|
+
}
|
|
801
|
+
|
|
784
802
|
/**
|
|
785
803
|
* Scroll to the selected version only when that selection changes.
|
|
786
804
|
* A page of older messages must not pull the list back to the latest turn.
|
|
@@ -791,10 +809,11 @@
|
|
|
791
809
|
const sha = widgetHeadCommitSha ?? '';
|
|
792
810
|
const key = `${version ?? ''}|${sha}`;
|
|
793
811
|
const turnCount = chatTurns.length;
|
|
794
|
-
|
|
812
|
+
const generating = isGenerating;
|
|
813
|
+
if (generating || (version == null && !sha) || !messagesContainer || turnCount === 0) return;
|
|
795
814
|
if (key === scrolledViewKey || pendingOlderScroll) return;
|
|
796
815
|
void tick().then(() => {
|
|
797
|
-
if (!messagesContainer || pendingOlderScroll) return;
|
|
816
|
+
if (!messagesContainer || pendingOlderScroll || isGenerating) return;
|
|
798
817
|
const here = messagesContainer.querySelector('[data-you-are-here="true"]');
|
|
799
818
|
if (!here) return;
|
|
800
819
|
scrollIntoViewWithin(messagesContainer, here);
|
|
@@ -912,13 +931,15 @@
|
|
|
912
931
|
}
|
|
913
932
|
const pinToBottom = shouldPinChatToBottom();
|
|
914
933
|
const messageCount = visibleMessages.length;
|
|
934
|
+
const streamLength = generationStream.length;
|
|
915
935
|
if (!initialBottomPinned && messagesContainer && messageCount > 0 && !pendingOlderScroll) {
|
|
916
936
|
void tick().then(() => settleMessagesToEnd());
|
|
917
937
|
}
|
|
918
|
-
if (messagesContainer && pinToBottom && messageCount > 0 && !pendingOlderScroll && initialBottomPinned) {
|
|
938
|
+
if (messagesContainer && pinToBottom && (messageCount > 0 || streamLength > 0) && !pendingOlderScroll && initialBottomPinned) {
|
|
919
939
|
tick().then(() => {
|
|
920
940
|
if (!messagesContainer || pendingOlderScroll || !shouldPinChatToBottom()) return;
|
|
921
941
|
scrollMessagesToEnd();
|
|
942
|
+
if (isGenerating) scrollGenerationTail();
|
|
922
943
|
});
|
|
923
944
|
}
|
|
924
945
|
});
|
|
@@ -1584,8 +1605,8 @@
|
|
|
1584
1605
|
<p class="text-gray-500 text-xs">{$t('chat.messages.loadingHistory')}</p>
|
|
1585
1606
|
</div>
|
|
1586
1607
|
</div>
|
|
1587
|
-
{:else if isLoading}
|
|
1588
|
-
<div class="loading-indicator-ct flex
|
|
1608
|
+
{:else if isLoading || isGenerating}
|
|
1609
|
+
<div class="loading-indicator-ct flex flex-col items-start gap-2 p-3">
|
|
1589
1610
|
<div class="rounded-lg shadow-sm text-sm leading-relaxed p-3"
|
|
1590
1611
|
style="background-color: {MESSAGE_COLORS.ASSISTANT}; color: {MESSAGE_COLORS.ASSISTANT_TEXT}"
|
|
1591
1612
|
>
|
|
@@ -1596,11 +1617,30 @@
|
|
|
1596
1617
|
size="md"
|
|
1597
1618
|
/>
|
|
1598
1619
|
</div>
|
|
1620
|
+
{#if isGenerating && generationStream}
|
|
1621
|
+
<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">{generationStream}</pre>
|
|
1622
|
+
{/if}
|
|
1599
1623
|
</div>
|
|
1600
1624
|
{/if}
|
|
1601
1625
|
</div>
|
|
1602
1626
|
|
|
1603
1627
|
<style>
|
|
1628
|
+
.generation-stream {
|
|
1629
|
+
scrollbar-width: thin;
|
|
1630
|
+
scrollbar-color: rgba(255, 255, 255, 0.35) transparent;
|
|
1631
|
+
}
|
|
1632
|
+
.generation-stream::-webkit-scrollbar {
|
|
1633
|
+
width: 8px;
|
|
1634
|
+
height: 8px;
|
|
1635
|
+
background: transparent;
|
|
1636
|
+
}
|
|
1637
|
+
.generation-stream::-webkit-scrollbar-track {
|
|
1638
|
+
background: transparent;
|
|
1639
|
+
}
|
|
1640
|
+
.generation-stream::-webkit-scrollbar-thumb {
|
|
1641
|
+
background: rgba(255, 255, 255, 0.35);
|
|
1642
|
+
border-radius: 4px;
|
|
1643
|
+
}
|
|
1604
1644
|
.loading {
|
|
1605
1645
|
opacity: 0.75;
|
|
1606
1646
|
}
|
|
@@ -49,6 +49,8 @@ interface Props {
|
|
|
49
49
|
showCommitMeta?: boolean;
|
|
50
50
|
/** True while codegen / send is in flight — suppresses premature Retry. */
|
|
51
51
|
isGenerating?: boolean;
|
|
52
|
+
/** Tail of the model stream for the generation in flight. Empty when it is only thinking. */
|
|
53
|
+
generationStream?: string;
|
|
52
54
|
onSuggestionSelected?: (suggestion: string) => void;
|
|
53
55
|
onRestoreCheckpoint?: (messageId: string, messageIndex: number) => void;
|
|
54
56
|
onRetryMessage?: (content: string) => void;
|