@widgetic/chat 0.1.5 → 0.1.7
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 +2 -5
- package/dist/components/ActionBar.svelte +6 -6
- package/dist/components/AttachmentDisplay.svelte +16 -5
- package/dist/components/Chat.svelte +375 -209
- package/dist/components/Chat.svelte.d.ts +14 -2
- package/dist/components/ChatInput.svelte +71 -17
- package/dist/components/ChatInput.svelte.d.ts +2 -0
- package/dist/components/ChatMessages.svelte +267 -113
- package/dist/components/ChatMessages.svelte.d.ts +3 -1
- package/dist/components/CodeBlock.svelte +146 -19
- package/dist/components/SuggestionButtons.svelte +1 -1
- package/dist/services/chatService.js +11 -11
- package/dist/stores/chatStore.js +4 -6
- package/dist/types/config.d.ts +2 -2
- package/dist/types/config.js +1 -1
- package/dist/utils/logger.js +2 -3
- package/package.json +7 -6
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ChatConfig, ChatContext } from '../types/index.js';
|
|
2
|
+
import type { AttachmentInput } from '../types/attachment.js';
|
|
2
3
|
interface ChatMethods {
|
|
3
|
-
sendMessage: (content: string, attachments?: File
|
|
4
|
+
sendMessage: (content: string, attachments?: Array<File | AttachmentInput>) => Promise<void>;
|
|
4
5
|
addAssistantMessage: (content: string, skipPersist?: boolean) => void;
|
|
5
6
|
addUserMessage: (content: string, attachments?: Array<{
|
|
6
7
|
id: string;
|
|
@@ -52,7 +53,10 @@ interface Props {
|
|
|
52
53
|
isCompleted?: boolean;
|
|
53
54
|
onStatsUpdate?: (messageCount: number, firstMessage: string | null) => void;
|
|
54
55
|
onChatReady?: (chatMethods: ChatMethods) => void;
|
|
55
|
-
onCompletionToggle?: (
|
|
56
|
+
onCompletionToggle?: (detail?: {
|
|
57
|
+
conversationId: string | null;
|
|
58
|
+
completed: boolean;
|
|
59
|
+
}) => void;
|
|
56
60
|
/** When provided, called instead of the built-in mock service for sending messages.
|
|
57
61
|
* The parent handles the actual API call and can push assistant messages via addAssistantMessage. */
|
|
58
62
|
onSendMessage?: (content: string, attachments?: Array<{
|
|
@@ -116,6 +120,14 @@ interface Props {
|
|
|
116
120
|
resizeExpandsContainer?: boolean;
|
|
117
121
|
/** Delta in pixels, plus the resulting chat container height (for parent-owned resize). */
|
|
118
122
|
onMessagesResize?: (deltaPx: number, nextContainerHeightPx?: number) => void;
|
|
123
|
+
/**
|
|
124
|
+
* Widget Git HEAD from the host (panel lastCommitId). Used so Head / Restore chrome
|
|
125
|
+
* still appears when assistant commit bubbles were never persisted.
|
|
126
|
+
*/
|
|
127
|
+
widgetHeadCommitSha?: string | null;
|
|
128
|
+
/** Host is running widget codegen — send button becomes stop. */
|
|
129
|
+
isGenerating?: boolean;
|
|
130
|
+
onStopGeneration?: () => void;
|
|
119
131
|
}
|
|
120
132
|
declare const Chat: import("svelte").Component<Props, {}, "">;
|
|
121
133
|
type Chat = ReturnType<typeof Chat>;
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
isRecording: boolean;
|
|
10
10
|
isSending: boolean;
|
|
11
11
|
isUploading: boolean;
|
|
12
|
+
isGenerating?: boolean;
|
|
12
13
|
onSend: (content: string, attachments?: AttachmentInput[]) => void;
|
|
14
|
+
onStop?: () => void;
|
|
13
15
|
onInputChange: (text: string) => void;
|
|
14
16
|
onAttachmentsChange: (attachments: AttachmentInput[]) => void;
|
|
15
17
|
placeholder?: string;
|
|
@@ -21,7 +23,9 @@
|
|
|
21
23
|
isRecording,
|
|
22
24
|
isSending,
|
|
23
25
|
isUploading,
|
|
24
|
-
|
|
26
|
+
isGenerating = false,
|
|
27
|
+
onSend,
|
|
28
|
+
onStop,
|
|
25
29
|
onInputChange,
|
|
26
30
|
onAttachmentsChange,
|
|
27
31
|
placeholder = "Type your message..."
|
|
@@ -30,11 +34,11 @@
|
|
|
30
34
|
let textArea: HTMLTextAreaElement;
|
|
31
35
|
|
|
32
36
|
onMount(() => {
|
|
33
|
-
chatLog('ChatInput mounted for value:', value);
|
|
37
|
+
// chatLog('ChatInput mounted for value:', value);
|
|
34
38
|
});
|
|
35
39
|
|
|
36
40
|
onDestroy(() => {
|
|
37
|
-
chatLog('ChatInput destroyed for value:', value);
|
|
41
|
+
// chatLog('ChatInput destroyed for value:', value);
|
|
38
42
|
});
|
|
39
43
|
|
|
40
44
|
function handleSubmit() {
|
|
@@ -58,11 +62,43 @@
|
|
|
58
62
|
}
|
|
59
63
|
}
|
|
60
64
|
|
|
65
|
+
const createdObjectUrls = new Set<string>();
|
|
66
|
+
|
|
67
|
+
function getAttachmentPreviewUrl(attachment: AttachmentInput): string {
|
|
68
|
+
if (attachment.preview) {
|
|
69
|
+
return attachment.preview;
|
|
70
|
+
}
|
|
71
|
+
const objectUrl = URL.createObjectURL(attachment.file);
|
|
72
|
+
createdObjectUrls.add(objectUrl);
|
|
73
|
+
attachment.preview = objectUrl;
|
|
74
|
+
return objectUrl;
|
|
75
|
+
}
|
|
76
|
+
|
|
61
77
|
function removeAttachment(index: number) {
|
|
78
|
+
const removed = attachments[index];
|
|
79
|
+
if (removed?.preview && removed.preview.startsWith('blob:')) {
|
|
80
|
+
try {
|
|
81
|
+
URL.revokeObjectURL(removed.preview);
|
|
82
|
+
createdObjectUrls.delete(removed.preview);
|
|
83
|
+
} catch {
|
|
84
|
+
/* ignore error */
|
|
85
|
+
}
|
|
86
|
+
}
|
|
62
87
|
const newAttachments = attachments.filter((_, i) => i !== index);
|
|
63
88
|
onAttachmentsChange(newAttachments);
|
|
64
89
|
}
|
|
65
90
|
|
|
91
|
+
onDestroy(() => {
|
|
92
|
+
for (const url of createdObjectUrls) {
|
|
93
|
+
try {
|
|
94
|
+
URL.revokeObjectURL(url);
|
|
95
|
+
} catch {
|
|
96
|
+
/* ignore error */
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
createdObjectUrls.clear();
|
|
100
|
+
});
|
|
101
|
+
|
|
66
102
|
let draggingAttachmentIndex: number | null = $state(null);
|
|
67
103
|
|
|
68
104
|
function handleAttachmentDragStart(index: number, e: DragEvent) {
|
|
@@ -98,8 +134,7 @@
|
|
|
98
134
|
let lightboxSrc: string | null = $state(null);
|
|
99
135
|
|
|
100
136
|
function openLightbox(attachment: AttachmentInput) {
|
|
101
|
-
|
|
102
|
-
lightboxSrc = src;
|
|
137
|
+
lightboxSrc = getAttachmentPreviewUrl(attachment);
|
|
103
138
|
}
|
|
104
139
|
|
|
105
140
|
// Auto-resize textarea up to max-height, then scroll
|
|
@@ -114,7 +149,7 @@
|
|
|
114
149
|
// Update textarea value when prop changes (for clearing)
|
|
115
150
|
$effect(() => {
|
|
116
151
|
if (textArea && textArea.value !== value) {
|
|
117
|
-
chatLog('ChatInput: Updating textarea value from', textArea.value, 'to', value);
|
|
152
|
+
// chatLog('ChatInput: Updating textarea value from', textArea.value, 'to', value);
|
|
118
153
|
textArea.value = value;
|
|
119
154
|
// Re-trigger auto-resize after value change
|
|
120
155
|
textArea.style.height = 'auto';
|
|
@@ -134,7 +169,7 @@
|
|
|
134
169
|
|
|
135
170
|
// Debug value changes
|
|
136
171
|
$effect(() => {
|
|
137
|
-
chatLog('ChatInput: Value prop changed to:', value);
|
|
172
|
+
// chatLog('ChatInput: Value prop changed to:', value);
|
|
138
173
|
});
|
|
139
174
|
</script>
|
|
140
175
|
|
|
@@ -143,6 +178,7 @@
|
|
|
143
178
|
{#if attachments.length > 0}
|
|
144
179
|
<div class="attachments-preview-ct flex flex-wrap gap-2 p-3 border-b border-gray-100 dark:border-gray-700">
|
|
145
180
|
{#each attachments as attachment, index}
|
|
181
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
146
182
|
<div
|
|
147
183
|
class="attachment-preview-item-ct relative bg-gray-50 dark:bg-gray-700 rounded-lg overflow-hidden"
|
|
148
184
|
draggable="true"
|
|
@@ -156,7 +192,7 @@
|
|
|
156
192
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
157
193
|
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
158
194
|
<img
|
|
159
|
-
src={
|
|
195
|
+
src={getAttachmentPreviewUrl(attachment)}
|
|
160
196
|
alt={attachment.file.name}
|
|
161
197
|
class="image-preview-ct w-16 h-16 object-cover cursor-pointer"
|
|
162
198
|
onclick={() => openLightbox(attachment)}
|
|
@@ -200,21 +236,33 @@
|
|
|
200
236
|
class="flex-1 bg-transparent border-none outline-none resize-y text-sm placeholder-gray-500 dark:text-gray-100 dark:placeholder-gray-400"
|
|
201
237
|
style="min-height: 30px; max-height: 120px; overflow-y: auto;"
|
|
202
238
|
rows="1"
|
|
203
|
-
disabled={isSending}
|
|
239
|
+
disabled={isSending && !isGenerating}
|
|
204
240
|
></textarea>
|
|
205
241
|
|
|
206
242
|
<div class="send-button-ct flex items-center gap-2">
|
|
207
243
|
<!-- Send Button -->
|
|
208
244
|
<button
|
|
209
|
-
class="send-button-btn w-8 h-8 rounded-lg
|
|
210
|
-
class:bg-
|
|
211
|
-
class:
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
245
|
+
class="send-button-btn w-8 h-8 rounded-lg flex items-center justify-center transition-colors"
|
|
246
|
+
class:bg-blue-600={!isGenerating}
|
|
247
|
+
class:hover:bg-blue-700={!isGenerating}
|
|
248
|
+
class:bg-red-600={isGenerating}
|
|
249
|
+
class:hover:bg-red-700={isGenerating}
|
|
250
|
+
class:bg-gray-300={!isGenerating && ((!value.trim() && attachments.length === 0) || isSending)}
|
|
251
|
+
class:cursor-not-allowed={!isGenerating && ((!value.trim() && attachments.length === 0) || isSending)}
|
|
252
|
+
onclick={() => {
|
|
253
|
+
if (isGenerating) {
|
|
254
|
+
onStop?.();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
handleSubmit();
|
|
258
|
+
}}
|
|
259
|
+
disabled={!isGenerating && ((!value.trim() && attachments.length === 0) || isSending)}
|
|
260
|
+
aria-label={isGenerating ? 'Stop generation' : (isSending ? 'Sending message...' : 'Send message')}
|
|
261
|
+
title={isGenerating ? 'Stop generation' : (isSending ? 'Sending message...' : 'Send message')}
|
|
216
262
|
>
|
|
217
|
-
{#if
|
|
263
|
+
{#if isGenerating}
|
|
264
|
+
<span class="block w-3 h-3 rounded-[2px] bg-white"></span>
|
|
265
|
+
{:else if isSending}
|
|
218
266
|
<svg class="w-4 h-4 animate-spin" viewBox="0 0 24 24">
|
|
219
267
|
<circle cx="12" cy="12" r="10" fill="none" stroke="white" stroke-width="2" opacity="0.3"/>
|
|
220
268
|
<path d="M22 12a10 10 0 0 1-10 10" fill="none" stroke="white" stroke-width="2" stroke-linecap="round"/>
|
|
@@ -245,6 +293,12 @@
|
|
|
245
293
|
{/if}
|
|
246
294
|
|
|
247
295
|
<style>
|
|
296
|
+
.send-button-btn:focus,
|
|
297
|
+
.send-button-btn:focus-visible {
|
|
298
|
+
outline: none;
|
|
299
|
+
box-shadow: none;
|
|
300
|
+
}
|
|
301
|
+
|
|
248
302
|
.input-lightbox-overlay {
|
|
249
303
|
position: fixed;
|
|
250
304
|
inset: 0;
|
|
@@ -5,7 +5,9 @@ interface Props {
|
|
|
5
5
|
isRecording: boolean;
|
|
6
6
|
isSending: boolean;
|
|
7
7
|
isUploading: boolean;
|
|
8
|
+
isGenerating?: boolean;
|
|
8
9
|
onSend: (content: string, attachments?: AttachmentInput[]) => void;
|
|
10
|
+
onStop?: () => void;
|
|
9
11
|
onInputChange: (text: string) => void;
|
|
10
12
|
onAttachmentsChange: (attachments: AttachmentInput[]) => void;
|
|
11
13
|
placeholder?: string;
|