@widgetic/chat 0.1.13 → 0.1.15
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.
- package/dist/adapters/widgeticAdapter.js +418 -530
- package/dist/components/AttachmentDisplay.svelte +11 -2
- package/dist/components/Chat.svelte +34 -13
- package/dist/components/Chat.svelte.d.ts +10 -0
- package/dist/components/ChatMessages.svelte +339 -44
- package/dist/components/ChatMessages.svelte.d.ts +14 -0
- package/dist/types/message.d.ts +6 -0
- package/package.json +1 -1
|
@@ -19,6 +19,15 @@
|
|
|
19
19
|
onRemove,
|
|
20
20
|
onView
|
|
21
21
|
}: Props = $props();
|
|
22
|
+
|
|
23
|
+
function portalToBody(node: HTMLElement) {
|
|
24
|
+
document.body.appendChild(node);
|
|
25
|
+
return {
|
|
26
|
+
destroy() {
|
|
27
|
+
node.remove();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
22
31
|
|
|
23
32
|
// Helper functions
|
|
24
33
|
function getFileIcon(fileType: string): string {
|
|
@@ -246,7 +255,7 @@
|
|
|
246
255
|
{#if lightboxAttachment}
|
|
247
256
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
248
257
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
249
|
-
<div class="lightbox-overlay" onclick={closeLightbox}>
|
|
258
|
+
<div class="lightbox-overlay" use:portalToBody onclick={closeLightbox}>
|
|
250
259
|
<button class="lightbox-close" onclick={closeLightbox} title="Close">✕</button>
|
|
251
260
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
252
261
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
@@ -494,7 +503,7 @@
|
|
|
494
503
|
.lightbox-overlay {
|
|
495
504
|
position: fixed;
|
|
496
505
|
inset: 0;
|
|
497
|
-
z-index:
|
|
506
|
+
z-index: 100000;
|
|
498
507
|
display: flex;
|
|
499
508
|
align-items: center;
|
|
500
509
|
justify-content: center;
|
|
@@ -96,6 +96,12 @@
|
|
|
96
96
|
* turn reads as the version it produced instead of a commit hash.
|
|
97
97
|
*/
|
|
98
98
|
versionLabelByCommitSha?: Record<string, string>;
|
|
99
|
+
/** User prompt text → "Version N", when the turn has no commit line. */
|
|
100
|
+
versionLabelByPrompt?: Record<string, string>;
|
|
101
|
+
/** Saved versions, so a prompt that produced two commits can show two turns. */
|
|
102
|
+
versionTimeline?: Array<{ version: number; sha: string; prompt: string }>;
|
|
103
|
+
/** Version selected in the dropdown. You-are-here follows this number. */
|
|
104
|
+
viewingVersion?: number | null;
|
|
99
105
|
/** Host is running widget codegen — send button becomes stop. */
|
|
100
106
|
isGenerating?: boolean;
|
|
101
107
|
onStopGeneration?: () => void;
|
|
@@ -136,12 +142,15 @@
|
|
|
136
142
|
updateLastUserMessageAttachments: (attachments: Array<{ id?: string; url: string; file_type?: string; file_name?: string | null }>) => void;
|
|
137
143
|
}
|
|
138
144
|
|
|
139
|
-
let { context, config = {}, class: className = '', style = '', isCompleted = false, onStatsUpdate, onChatReady, onCompletionToggle, onSendMessage, onLoadConversations, onLoadMessages, onCreateConversation, onSaveMessage, onRestoreCheckpointBackend, onTakeScreenshot, onConversationChange, onDraftChange, onRetryMessage, onUploadChatFile, showHeader = true, headerTitle = '', showDescriptionHeader = true, showLogs = true, resizeExpandsContainer = false, onMessagesResize, widgetHeadCommitSha = null, versionLabelByCommitSha = {}, isGenerating = false, onStopGeneration }: Props = $props();
|
|
145
|
+
let { context, config = {}, class: className = '', style = '', isCompleted = false, onStatsUpdate, onChatReady, onCompletionToggle, onSendMessage, onLoadConversations, onLoadMessages, onCreateConversation, onSaveMessage, onRestoreCheckpointBackend, onTakeScreenshot, onConversationChange, onDraftChange, onRetryMessage, onUploadChatFile, showHeader = true, headerTitle = '', showDescriptionHeader = true, showLogs = true, resizeExpandsContainer = false, onMessagesResize, widgetHeadCommitSha = null, versionLabelByCommitSha = {}, versionLabelByPrompt = {}, versionTimeline = [], viewingVersion = null, isGenerating = false, onStopGeneration }: Props = $props();
|
|
140
146
|
|
|
141
147
|
function notifyDraftChange() {
|
|
142
148
|
onDraftChange?.();
|
|
143
149
|
}
|
|
144
150
|
|
|
151
|
+
const promptVersionLabels = $derived(versionLabelByPrompt ?? {});
|
|
152
|
+
const selectedViewingVersion = $derived(viewingVersion ?? null);
|
|
153
|
+
|
|
145
154
|
// Apply log suppression immediately
|
|
146
155
|
$effect(() => {
|
|
147
156
|
setLogsEnabled(showLogs);
|
|
@@ -503,7 +512,7 @@
|
|
|
503
512
|
activeConversationId,
|
|
504
513
|
submittedContent,
|
|
505
514
|
'user',
|
|
506
|
-
persistAttachments.length > 0 ? persistAttachments :
|
|
515
|
+
persistAttachments.length > 0 ? persistAttachments : undefined,
|
|
507
516
|
);
|
|
508
517
|
if (saved?.id && saved.id !== userMessage.id) {
|
|
509
518
|
chatStore.actions.updateMessageId(activeConversationId, userMessage.id, saved.id);
|
|
@@ -980,6 +989,16 @@
|
|
|
980
989
|
await sendMessage(retryContent);
|
|
981
990
|
}
|
|
982
991
|
|
|
992
|
+
function versionLabelForCommitContent(content?: string | null): string | null {
|
|
993
|
+
const match = String(content || '').match(/(?:Commit:?\s+|commit\s+id:\s+|Code saved\s*\()([a-f0-9]{7,40})/i);
|
|
994
|
+
const sha = match?.[1]?.toLowerCase();
|
|
995
|
+
if (!sha) return null;
|
|
996
|
+
return versionLabelByCommitSha[sha]
|
|
997
|
+
?? versionLabelByCommitSha[sha.slice(0, 8)]
|
|
998
|
+
?? versionLabelByCommitSha[sha.slice(0, 7)]
|
|
999
|
+
?? null;
|
|
1000
|
+
}
|
|
1001
|
+
|
|
983
1002
|
async function handleRestoreCheckpoint(messageId: string, messageIndex: number) {
|
|
984
1003
|
// chatLog('Restore checkpoint requested:', { messageId, messageIndex, conversationId: currentConversationId });
|
|
985
1004
|
|
|
@@ -1022,21 +1041,19 @@
|
|
|
1022
1041
|
}
|
|
1023
1042
|
}
|
|
1024
1043
|
|
|
1025
|
-
const
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
}));
|
|
1030
|
-
|
|
1031
|
-
// chatLog(`Restoring to checkpoint user message ${checkpointUserId}, head assistant ${headAssistantId}`);
|
|
1032
|
-
chatStore.actions.setMessages(currentConversationId, updatedMessages);
|
|
1044
|
+
const checkpointUser = currentMessages.find((msg: any) => msg.id === checkpointUserId);
|
|
1045
|
+
const headAssistant = currentMessages.find((msg: any) => msg.id === headAssistantId);
|
|
1046
|
+
const sourceLabel = versionLabelForCommitContent(headAssistant?.messageContent) || 'a previous version';
|
|
1047
|
+
const promptCopy = String(checkpointUser?.messageContent || '').trim();
|
|
1033
1048
|
|
|
1034
1049
|
if (onRestoreCheckpointBackend) {
|
|
1035
1050
|
try {
|
|
1036
1051
|
const result = await onRestoreCheckpointBackend(currentConversationId, checkpointUserId);
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1052
|
+
const rollback = result?.gitRollback || result?.git_rollback || result?.data?.gitRollback || result?.data?.git_rollback;
|
|
1053
|
+
const newSha = String(rollback?.commitId || rollback?.commit_id || '').trim();
|
|
1054
|
+
if (rollback?.success && newSha && promptCopy) {
|
|
1055
|
+
addUserMessage(promptCopy);
|
|
1056
|
+
addAssistantMessage(`Restored from ${sourceLabel}\n\nCommit: ${newSha.slice(0, 8)}`);
|
|
1040
1057
|
}
|
|
1041
1058
|
} catch (backendError) {
|
|
1042
1059
|
console.error('[Chat] Backend checkpoint restore failed, local state updated:', backendError);
|
|
@@ -1173,6 +1190,7 @@
|
|
|
1173
1190
|
/^Code generation completed/i.test(trimmed) ||
|
|
1174
1191
|
/^Compile fix applied/i.test(trimmed) ||
|
|
1175
1192
|
/^Code saved/i.test(trimmed) ||
|
|
1193
|
+
/^Restored from /i.test(trimmed) ||
|
|
1176
1194
|
isBackendCodegenSummary(trimmed)
|
|
1177
1195
|
)) {
|
|
1178
1196
|
return true;
|
|
@@ -1606,6 +1624,9 @@
|
|
|
1606
1624
|
showGenerationSummaries={config?.features?.showGenerationSummaries === true}
|
|
1607
1625
|
widgetHeadCommitSha={widgetHeadCommitSha}
|
|
1608
1626
|
versionLabelByCommitSha={versionLabelByCommitSha}
|
|
1627
|
+
versionLabelByPrompt={promptVersionLabels}
|
|
1628
|
+
{versionTimeline}
|
|
1629
|
+
viewingVersion={selectedViewingVersion}
|
|
1609
1630
|
showCommitMeta={showLogs}
|
|
1610
1631
|
isGenerating={isGenerating || isLoading}
|
|
1611
1632
|
onSuggestionSelected={handleSuggestionSelected}
|
|
@@ -141,6 +141,16 @@ interface Props {
|
|
|
141
141
|
* turn reads as the version it produced instead of a commit hash.
|
|
142
142
|
*/
|
|
143
143
|
versionLabelByCommitSha?: Record<string, string>;
|
|
144
|
+
/** User prompt text → "Version N", when the turn has no commit line. */
|
|
145
|
+
versionLabelByPrompt?: Record<string, string>;
|
|
146
|
+
/** Saved versions, so a prompt that produced two commits can show two turns. */
|
|
147
|
+
versionTimeline?: Array<{
|
|
148
|
+
version: number;
|
|
149
|
+
sha: string;
|
|
150
|
+
prompt: string;
|
|
151
|
+
}>;
|
|
152
|
+
/** Version selected in the dropdown. You-are-here follows this number. */
|
|
153
|
+
viewingVersion?: number | null;
|
|
144
154
|
/** Host is running widget codegen — send button becomes stop. */
|
|
145
155
|
isGenerating?: boolean;
|
|
146
156
|
onStopGeneration?: () => void;
|