@widgetic/chat 0.1.7 → 0.1.8

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.
@@ -1,6 +1,4 @@
1
1
  <script lang="ts">
2
- import { createEventDispatcher } from 'svelte';
3
- import { chatLog } from '../utils/logger.js';
4
2
  import type { ChatContext } from '../types/context.js';
5
3
 
6
4
  // Props
@@ -14,6 +12,12 @@
14
12
  showRecord?: boolean;
15
13
  showUpload?: boolean;
16
14
  showComplete?: boolean;
15
+ onScreenshot?: () => void;
16
+ onUpload?: () => void;
17
+ onRecordStart?: () => void;
18
+ onRecordStop?: () => void;
19
+ onComplete?: (detail: { completed: boolean }) => void;
20
+ onError?: (detail: { type: string; error: unknown }) => void;
17
21
  }
18
22
 
19
23
  let {
@@ -26,20 +30,23 @@
26
30
  showRecord = true,
27
31
  showUpload = true,
28
32
  showComplete = true,
33
+ onScreenshot,
34
+ onUpload,
35
+ onRecordStart,
36
+ onRecordStop,
37
+ onComplete,
38
+ onError,
29
39
  }: Props = $props();
30
40
 
31
- const dispatch = createEventDispatcher();
32
-
33
- // Handle screenshot capture
41
+ // Handle screenshot capture — attachments do not require an existing conversation.
34
42
  async function handleScreenshot() {
35
- if (disabled || !conversationId) return;
43
+ if (disabled) return;
36
44
 
37
45
  try {
38
- // chatLog('Triggering screenshot for context:', context.id);
39
- dispatch('screenshot', { contextId: context.id });
46
+ onScreenshot?.();
40
47
  } catch (error) {
41
48
  console.error('Screenshot failed:', error);
42
- dispatch('error', { type: 'screenshot', error });
49
+ onError?.({ type: 'screenshot', error });
43
50
  }
44
51
  }
45
52
 
@@ -49,56 +56,28 @@
49
56
 
50
57
  try {
51
58
  if (isRecording) {
52
- // chatLog('Stopping recording for context:', context.id);
53
- dispatch('recordStop', { contextId: context.id });
59
+ onRecordStop?.();
54
60
  } else {
55
- // chatLog('Starting recording for context:', context.id);
56
- dispatch('recordStart', { contextId: context.id });
61
+ onRecordStart?.();
57
62
  }
58
63
  } catch (error) {
59
64
  console.error('Recording action failed:', error);
60
- dispatch('error', { type: 'recording', error });
65
+ onError?.({ type: 'recording', error });
61
66
  }
62
67
  }
63
68
 
64
- // Handle file upload
69
+ // Handle file upload — same as screenshot: works before conversation exists.
65
70
  function handleUpload() {
66
- if (disabled || !conversationId) return;
71
+ if (disabled) return;
67
72
 
68
- // chatLog('Triggering file upload');
69
- dispatch('upload');
73
+ onUpload?.();
70
74
  }
71
75
 
72
76
  // Handle completion toggle
73
77
  function handleCompletionToggle() {
74
78
  if (disabled || !conversationId) return;
75
79
 
76
- // chatLog('Toggling conversation completion:', !isCompleted);
77
- dispatch('complete', { completed: !isCompleted });
78
- }
79
-
80
- // Get context-specific suggestions
81
- function getContextSuggestions(): string[] {
82
- switch (context.type) {
83
- case 'frame':
84
- return [
85
- 'Generate code from this design',
86
- 'Explain this component structure',
87
- 'Suggest improvements for this layout'
88
- ];
89
- case 'text':
90
- return [
91
- 'Help improve this writing',
92
- 'Check grammar and style',
93
- 'Suggest alternative phrasing'
94
- ];
95
- default:
96
- return [
97
- 'Ask a question about this content',
98
- 'Get suggestions for improvement',
99
- 'Explain what you see here'
100
- ];
101
- }
80
+ onComplete?.({ completed: !isCompleted });
102
81
  }
103
82
  </script>
104
83
 
@@ -108,7 +87,7 @@
108
87
  <button
109
88
  class="action-button screenshot-button"
110
89
  onclick={handleScreenshot}
111
- disabled={disabled || !conversationId}
90
+ disabled={disabled}
112
91
  title="Take Screenshot"
113
92
  aria-label="Take screenshot of current content"
114
93
  >
@@ -151,7 +130,7 @@
151
130
  <button
152
131
  class="action-button upload-button"
153
132
  onclick={handleUpload}
154
- disabled={disabled || !conversationId}
133
+ disabled={disabled}
155
134
  title="Upload File"
156
135
  aria-label="Upload file"
157
136
  >
@@ -339,4 +318,4 @@
339
318
  height: 1.5rem;
340
319
  }
341
320
  }
342
- </style>
321
+ </style>
@@ -9,29 +9,18 @@ interface Props {
9
9
  showRecord?: boolean;
10
10
  showUpload?: boolean;
11
11
  showComplete?: boolean;
12
+ onScreenshot?: () => void;
13
+ onUpload?: () => void;
14
+ onRecordStart?: () => void;
15
+ onRecordStop?: () => void;
16
+ onComplete?: (detail: {
17
+ completed: boolean;
18
+ }) => void;
19
+ onError?: (detail: {
20
+ type: string;
21
+ error: unknown;
22
+ }) => void;
12
23
  }
13
- interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
14
- new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
15
- $$bindings?: Bindings;
16
- } & Exports;
17
- (internal: unknown, props: Props & {
18
- $$events?: Events;
19
- $$slots?: Slots;
20
- }): Exports & {
21
- $set?: any;
22
- $on?: any;
23
- };
24
- z_$$bindings?: Bindings;
25
- }
26
- declare const ActionBar: $$__sveltets_2_IsomorphicComponent<Props, {
27
- screenshot: CustomEvent<any>;
28
- error: CustomEvent<any>;
29
- recordStop: CustomEvent<any>;
30
- recordStart: CustomEvent<any>;
31
- upload: CustomEvent<any>;
32
- complete: CustomEvent<any>;
33
- } & {
34
- [evt: string]: CustomEvent<any>;
35
- }, {}, {}, "">;
36
- type ActionBar = InstanceType<typeof ActionBar>;
24
+ declare const ActionBar: import("svelte").Component<Props, {}, "">;
25
+ type ActionBar = ReturnType<typeof ActionBar>;
37
26
  export default ActionBar;
@@ -362,13 +362,19 @@
362
362
  const conversation = onCreateConversation
363
363
  ? await onCreateConversation(context.id, defaultTitle)
364
364
  : await chatService.createConversation(context.id, { title: defaultTitle });
365
-
365
+
366
+ const conversationId =
367
+ conversation && typeof conversation.id === 'string' ? conversation.id.trim() : '';
368
+ if (!conversation || !conversationId) {
369
+ throw new Error('Failed to create conversation');
370
+ }
371
+
366
372
  chatStore.dispatch({
367
373
  type: 'ADD_CONVERSATION',
368
374
  payload: { contextId: context.id, conversation }
369
375
  });
370
-
371
- currentConversationId = conversation.id;
376
+
377
+ currentConversationId = conversationId;
372
378
  return conversation;
373
379
  } catch (error) {
374
380
  console.error('Failed to create conversation:', error);
@@ -412,6 +418,10 @@
412
418
  console.error('No active conversation and failed to create one:', convErr);
413
419
  return;
414
420
  }
421
+ if (!currentConversationId) {
422
+ console.error('No active conversation after create');
423
+ return;
424
+ }
415
425
  }
416
426
  }
417
427
 
@@ -601,9 +611,9 @@
601
611
  }
602
612
  }
603
613
 
604
- // ActionBar event handlers
605
- async function handleScreenshot({ detail }: { detail: { contextId: string } }) {
606
- // chatLog('[Chat] Screenshot requested for context:', detail.contextId);
614
+ // ActionBar callback handlers (Svelte 5 — no createEventDispatcher)
615
+ async function handleScreenshot() {
616
+ // chatLog('[Chat] Screenshot requested for context:', context.id);
607
617
 
608
618
  try {
609
619
  let screenshotDataUrl: string | null = null;
@@ -633,6 +643,9 @@
633
643
  localAttachments = [...localAttachments, attachmentInput];
634
644
  const attachmentIndex = localAttachments.length - 1;
635
645
  notifyDraftChange();
646
+ expandChatForAttachmentGrowth(attachmentIndex);
647
+ chatStore.actions.updateUI({ errorMessage: null });
648
+ console.log('[Chat] attachments now', localAttachments.length);
636
649
 
637
650
  if (onUploadChatFile) {
638
651
  await uploadAttachmentToCdn(screenshotFile, attachmentInput, attachmentIndex, {
@@ -649,8 +662,8 @@
649
662
  }
650
663
  }
651
664
 
652
- async function handleRecordStart({ detail }: { detail: { contextId: string } }) {
653
- // chatLog('Recording start requested for context:', detail.contextId);
665
+ async function handleRecordStart() {
666
+ // chatLog('Recording start requested for context:', context.id);
654
667
 
655
668
  try {
656
669
  localIsRecording = true;
@@ -667,8 +680,8 @@
667
680
  }
668
681
  }
669
682
 
670
- async function handleRecordStop({ detail }: { detail: { contextId: string } }) {
671
- // chatLog('Recording stop requested for context:', detail.contextId);
683
+ async function handleRecordStop() {
684
+ // chatLog('Recording stop requested for context:', context.id);
672
685
 
673
686
  try {
674
687
  localIsRecording = false;
@@ -687,6 +700,7 @@
687
700
 
688
701
  // Add to attachments
689
702
  localAttachments = [...localAttachments, attachmentInput];
703
+ console.log('[Chat] attachments now', localAttachments.length);
690
704
 
691
705
  // chatLog('Recording stopped and added to attachments');
692
706
 
@@ -758,6 +772,90 @@
758
772
  }
759
773
  }
760
774
 
775
+ function expandChatForAttachmentGrowth(previousCount: number) {
776
+ if (localAttachments.length <= previousCount) return;
777
+
778
+ // When the first attachment appears, free space in a fixed messages area so the footer tray stays visible.
779
+ if (previousCount === 0 && messagesAreaHeight !== null) {
780
+ messagesAreaHeight = Math.max(120, messagesAreaHeight - 120);
781
+ }
782
+
783
+ if (!resizeExpandsContainer) return;
784
+ // Grow the fixed-height host once per net attachment increase so the tray is not clipped.
785
+ onMessagesResize?.(120);
786
+ chatLog('[Chat] Expanded chat host for attachments:', previousCount, '→', localAttachments.length);
787
+ }
788
+
789
+ function isImageAttachment(attachment: AttachmentInput): boolean {
790
+ return (
791
+ attachment.type === 'image' ||
792
+ !!attachment.file?.type?.startsWith('image/')
793
+ );
794
+ }
795
+
796
+ function getFooterAttachmentPreviewUrl(attachment: AttachmentInput): string {
797
+ if (attachment.preview) return attachment.preview;
798
+ if (attachment.uploadedUrl) return attachment.uploadedUrl;
799
+ if (!attachment.file) return '';
800
+ try {
801
+ const objectUrl = URL.createObjectURL(attachment.file);
802
+ attachment.preview = objectUrl;
803
+ return objectUrl;
804
+ } catch {
805
+ return '';
806
+ }
807
+ }
808
+
809
+ function removeFooterAttachment(index: number) {
810
+ const removed = localAttachments[index];
811
+ if (removed?.preview && removed.preview.startsWith('blob:')) {
812
+ try {
813
+ URL.revokeObjectURL(removed.preview);
814
+ } catch {
815
+ /* ignore error */
816
+ }
817
+ }
818
+ localAttachments = localAttachments.filter((_, i) => i !== index);
819
+ notifyDraftChange();
820
+ chatLog('[Chat] Removed footer attachment at index:', index);
821
+ }
822
+
823
+ let footerLightboxSrc: string | null = $state(null);
824
+
825
+ async function addFilesAsAttachments(files: File[]) {
826
+ const usableFiles = (files || []).filter((file) => file && file.size > 0);
827
+ if (usableFiles.length === 0) return;
828
+
829
+ const previousCount = localAttachments.length;
830
+ const newAttachments: AttachmentInput[] = usableFiles.map((file) => ({
831
+ file,
832
+ type: file.type.startsWith('image/')
833
+ ? 'image'
834
+ : file.type.startsWith('video/')
835
+ ? 'video'
836
+ : 'document',
837
+ uploadProgress: 0,
838
+ }));
839
+
840
+ const startIndex = localAttachments.length;
841
+ localAttachments = [...localAttachments, ...newAttachments];
842
+ notifyDraftChange();
843
+ expandChatForAttachmentGrowth(previousCount);
844
+ chatStore.actions.updateUI({ errorMessage: null });
845
+ console.log('[Chat] attachments now', localAttachments.length);
846
+
847
+ try {
848
+ localIsUploading = true;
849
+ for (let i = 0; i < usableFiles.length; i++) {
850
+ await uploadAttachmentToCdn(usableFiles[i], newAttachments[i], startIndex + i);
851
+ }
852
+ } finally {
853
+ localIsUploading = false;
854
+ }
855
+
856
+ chatLog('[Chat] Files added as attachments:', usableFiles.length);
857
+ }
858
+
761
859
  async function handleUpload() {
762
860
  // chatLog('File upload requested');
763
861
 
@@ -768,40 +866,13 @@
768
866
 
769
867
  fileInput.onchange = async (event) => {
770
868
  const files = Array.from((event.target as HTMLInputElement).files || []);
771
- if (files.length === 0) return;
772
-
773
- const newAttachments: AttachmentInput[] = files.map((file) => ({
774
- file,
775
- type: file.type.startsWith('image/')
776
- ? 'image'
777
- : file.type.startsWith('video/')
778
- ? 'video'
779
- : 'document',
780
- uploadProgress: 0,
781
- }));
782
-
783
- const startIndex = localAttachments.length;
784
- localAttachments = [...localAttachments, ...newAttachments];
785
- notifyDraftChange();
786
-
787
- try {
788
- localIsUploading = true;
789
- for (let i = 0; i < files.length; i++) {
790
- const file = files[i];
791
- const entry = newAttachments[i];
792
- await uploadAttachmentToCdn(file, entry, startIndex + i);
793
- }
794
- } finally {
795
- localIsUploading = false;
796
- }
797
-
798
- // chatLog('Files selected via upload:', files.length);
869
+ await addFilesAsAttachments(files);
799
870
  };
800
871
 
801
872
  fileInput.click();
802
873
  }
803
874
 
804
- async function handleComplete({ detail }: { detail: { completed: boolean } }) {
875
+ async function handleComplete(detail: { completed: boolean }) {
805
876
  // chatLog('Conversation completion toggle requested', {
806
877
  // conversationId: currentConversationId,
807
878
  // completed: detail?.completed,
@@ -830,7 +901,7 @@
830
901
  }
831
902
  }
832
903
 
833
- function handleActionError({ detail }: { detail: { type: string; error: any } }) {
904
+ function handleActionError(detail: { type: string; error: unknown }) {
834
905
  console.error(`ActionBar ${detail.type} error:`, detail.error);
835
906
  chatStore.actions.updateUI({
836
907
  errorMessage: `${detail.type} action failed. Please try again.`
@@ -962,6 +1033,7 @@
962
1033
  const attachmentIndex = localAttachments.length;
963
1034
  localAttachments = [...localAttachments, attachmentInput];
964
1035
  notifyDraftChange();
1036
+ expandChatForAttachmentGrowth(attachmentIndex);
965
1037
  if (onUploadChatFile) {
966
1038
  await uploadAttachmentToCdn(file, attachmentInput, attachmentIndex);
967
1039
  }
@@ -1405,7 +1477,7 @@
1405
1477
 
1406
1478
  <div
1407
1479
  bind:this={chatContainer}
1408
- class="{className ? className : 'prompt-chat-ct'} relative flex flex-col overflow-hidden bg-white border border-gray-300 rounded-medium {resizeExpandsContainer ? 'shrink-0' : 'h-full'}"
1480
+ class="{className ? className : 'prompt-chat-ct'} relative flex flex-col overflow-hidden bg-white border border-gray-300 {className ? '' : 'rounded-medium'} h-full min-h-0"
1409
1481
  style={style}
1410
1482
  >
1411
1483
  {#if showHeader}
@@ -1454,6 +1526,8 @@
1454
1526
  enableAutoCodeDetection={config?.features?.autoCodeDetection === true}
1455
1527
  showGenerationSummaries={config?.features?.showGenerationSummaries === true}
1456
1528
  widgetHeadCommitSha={widgetHeadCommitSha}
1529
+ showCommitMeta={showLogs}
1530
+ isGenerating={isGenerating || isLoading}
1457
1531
  onSuggestionSelected={handleSuggestionSelected}
1458
1532
  onRestoreCheckpoint={handleRestoreCheckpoint}
1459
1533
  onRetryMessage={handleRetryMessage}
@@ -1474,46 +1548,122 @@
1474
1548
  <div class="drag-grip w-14 h-1 rounded-full bg-gray-500 {isResizingMessages ? 'bg-blue-400' : ''}"></div>
1475
1549
  </div>
1476
1550
 
1477
- <ActionBar
1478
- {context}
1479
- conversationId={currentConversationId}
1480
- isRecording={localIsRecording}
1481
- isCompleted={isCompleted}
1482
- disabled={isLoading}
1483
- showScreenshot={config?.features?.screenshot !== false}
1484
- showRecord={config?.features?.screenRecording !== false}
1485
- showUpload={config?.features?.fileUpload !== false}
1486
- showComplete={config?.features?.markComplete !== false}
1487
- on:screenshot={handleScreenshot}
1488
- on:recordStart={handleRecordStart}
1489
- on:recordStop={handleRecordStop}
1490
- on:upload={handleUpload}
1491
- on:complete={handleComplete}
1492
- on:error={handleActionError}
1493
- />
1551
+ <div class="prompt-chat-footer-ct shrink-0 flex flex-col">
1552
+ <ActionBar
1553
+ {context}
1554
+ conversationId={currentConversationId}
1555
+ isRecording={localIsRecording}
1556
+ isCompleted={isCompleted}
1557
+ disabled={isLoading}
1558
+ showScreenshot={config?.features?.screenshot !== false}
1559
+ showRecord={config?.features?.screenRecording !== false}
1560
+ showUpload={config?.features?.fileUpload !== false}
1561
+ showComplete={config?.features?.markComplete !== false}
1562
+ onScreenshot={() => void handleScreenshot()}
1563
+ onUpload={() => void handleUpload()}
1564
+ onRecordStart={() => void handleRecordStart()}
1565
+ onRecordStop={() => void handleRecordStop()}
1566
+ onComplete={(detail) => void handleComplete(detail)}
1567
+ onError={handleActionError}
1568
+ />
1569
+
1570
+ {#if localAttachments.length > 0}
1571
+ <div class="prompt-chat-attachments-tray-ct flex flex-wrap gap-2 p-3 border-t border-gray-100 bg-white shrink-0">
1572
+ {#each localAttachments as attachment, index (attachment.preview || attachment.uploadedUrl || attachment.file?.name || index)}
1573
+ <div class="prompt-chat-attachment-item-ct relative bg-gray-50 rounded-lg overflow-hidden">
1574
+ <span class="prompt-chat-attachment-index-badge absolute top-0.5 left-0.5 z-10 w-4 h-4 flex items-center justify-center rounded-full bg-blue-600 text-white text-[9px] font-bold shadow">{index + 1}</span>
1575
+ {#if isImageAttachment(attachment)}
1576
+ <!-- svelte-ignore a11y_click_events_have_key_events -->
1577
+ <!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
1578
+ <img
1579
+ src={getFooterAttachmentPreviewUrl(attachment)}
1580
+ alt={attachment.file?.name || 'attachment'}
1581
+ class="prompt-chat-attachment-image-preview w-16 h-16 object-cover cursor-pointer"
1582
+ onclick={() => {
1583
+ const previewUrl = getFooterAttachmentPreviewUrl(attachment);
1584
+ if (previewUrl) footerLightboxSrc = previewUrl;
1585
+ }}
1586
+ />
1587
+ {:else}
1588
+ <div class="prompt-chat-attachment-file-preview flex items-center gap-2 p-3 w-32">
1589
+ <span class="text-lg">📄</span>
1590
+ <span class="text-xs text-gray-600 truncate flex-1">{attachment.file?.name || 'attachment'}</span>
1591
+ </div>
1592
+ {/if}
1593
+
1594
+ <button
1595
+ type="button"
1596
+ class="prompt-chat-remove-attachment-btn absolute top-1 right-1 w-5 h-5 bg-red-500 text-white rounded-full flex items-center justify-center text-xs hover:bg-red-600 cursor-pointer"
1597
+ onclick={() => removeFooterAttachment(index)}
1598
+ aria-label="Remove attachment"
1599
+ >
1600
+ ✕
1601
+ </button>
1602
+
1603
+ {#if attachment.uploadProgress && attachment.uploadProgress > 0 && attachment.uploadProgress < 100}
1604
+ <div class="prompt-chat-attachment-upload-bar absolute bottom-0 left-0 right-0 h-1 bg-gray-200">
1605
+ <div class="h-full bg-blue-500 transition-all duration-300" style="width: {attachment.uploadProgress}%"></div>
1606
+ </div>
1607
+ {/if}
1608
+ </div>
1609
+ {/each}
1610
+ </div>
1611
+ {/if}
1494
1612
 
1495
- <ChatInput
1496
- value={localInputText}
1497
- attachments={localAttachments}
1498
- isRecording={localIsRecording}
1499
- isSending={localIsSending}
1500
- isUploading={localIsUploading}
1501
- isGenerating={isGenerating || isLoading}
1502
- onStop={() => onStopGeneration?.()}
1503
- onSend={(content, attachmentInputs) => {
1504
- sendMessage(content, attachmentInputs);
1505
- }}
1506
- onInputChange={(text) => {
1507
- // chatLog('Input change for chat', context.id, ':', text);
1508
- localInputText = text;
1509
- notifyDraftChange();
1510
- }}
1511
- onAttachmentsChange={(attachments) => {
1512
- // chatLog('Attachments change for chat', context.id, ':', attachments.length);
1513
- localAttachments = attachments;
1514
- notifyDraftChange();
1515
- }}
1516
- />
1613
+ <ChatInput
1614
+ value={localInputText}
1615
+ attachments={localAttachments}
1616
+ showAttachmentsTray={false}
1617
+ isRecording={localIsRecording}
1618
+ isSending={localIsSending}
1619
+ isUploading={localIsUploading}
1620
+ isGenerating={isGenerating || isLoading}
1621
+ onStop={() => onStopGeneration?.()}
1622
+ onSend={(content, attachmentInputs) => {
1623
+ sendMessage(content, attachmentInputs);
1624
+ }}
1625
+ onInputChange={(text) => {
1626
+ // chatLog('Input change for chat', context.id, ':', text);
1627
+ localInputText = text;
1628
+ notifyDraftChange();
1629
+ }}
1630
+ onAttachmentsChange={(attachments) => {
1631
+ // chatLog('Attachments change for chat', context.id, ':', attachments.length);
1632
+ localAttachments = attachments;
1633
+ notifyDraftChange();
1634
+ }}
1635
+ onFilesDropped={(files) => {
1636
+ void addFilesAsAttachments(files);
1637
+ }}
1638
+ />
1639
+ </div>
1640
+
1641
+ {#if footerLightboxSrc}
1642
+ <!-- svelte-ignore a11y_click_events_have_key_events -->
1643
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
1644
+ <div
1645
+ class="prompt-chat-footer-lightbox-overlay fixed inset-0 z-[9999] flex items-center justify-center bg-black/85"
1646
+ onclick={() => (footerLightboxSrc = null)}
1647
+ >
1648
+ <button
1649
+ type="button"
1650
+ class="prompt-chat-footer-lightbox-close-btn absolute top-4 right-4 w-9 h-9 rounded-full bg-white/15 text-white text-lg flex items-center justify-center cursor-pointer hover:bg-white/30"
1651
+ onclick={() => (footerLightboxSrc = null)}
1652
+ title="Close"
1653
+ >
1654
+ ✕
1655
+ </button>
1656
+ <!-- svelte-ignore a11y_click_events_have_key_events -->
1657
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
1658
+ <div class="prompt-chat-footer-lightbox-content max-w-[90vw] max-h-[90vh]" onclick={(e) => e.stopPropagation()}>
1659
+ <img
1660
+ src={footerLightboxSrc}
1661
+ alt="Attachment preview"
1662
+ class="prompt-chat-footer-lightbox-image max-w-[90vw] max-h-[85vh] object-contain rounded-lg"
1663
+ />
1664
+ </div>
1665
+ </div>
1666
+ {/if}
1517
1667
 
1518
1668
  <!-- Error Display -->
1519
1669
  {#if ui?.errorMessage}
@@ -10,11 +10,20 @@
10
10
  isSending: boolean;
11
11
  isUploading: boolean;
12
12
  isGenerating?: boolean;
13
+ /**
14
+ * When false, skip the in-input attachments tray (parent renders it in the chat footer).
15
+ * Drag-drop on `.chat-input-ct` still works.
16
+ */
17
+ showAttachmentsTray?: boolean;
13
18
  onSend: (content: string, attachments?: AttachmentInput[]) => void;
14
19
  onStop?: () => void;
15
20
  onInputChange: (text: string) => void;
16
21
  onAttachmentsChange: (attachments: AttachmentInput[]) => void;
22
+ /** OS file drag-and-drop onto the input area (not attachment reorder). */
23
+ onFilesDropped?: (files: File[]) => void;
17
24
  placeholder?: string;
25
+ class?: string;
26
+ style?: string;
18
27
  }
19
28
 
20
29
  let {
@@ -24,13 +33,56 @@
24
33
  isSending,
25
34
  isUploading,
26
35
  isGenerating = false,
36
+ showAttachmentsTray = true,
27
37
  onSend,
28
38
  onStop,
29
39
  onInputChange,
30
40
  onAttachmentsChange,
31
- placeholder = "Type your message..."
41
+ onFilesDropped,
42
+ placeholder = "Type your message...",
43
+ class: className = '',
44
+ style = '',
32
45
  }: Props = $props();
33
46
 
47
+ let isFileDragOver = $state(false);
48
+
49
+ function isOsFileDrag(event: DragEvent): boolean {
50
+ return !!event.dataTransfer?.types?.includes('Files');
51
+ }
52
+
53
+ function handleFileDragEnter(event: DragEvent) {
54
+ if (!isOsFileDrag(event)) return;
55
+ event.preventDefault();
56
+ isFileDragOver = true;
57
+ }
58
+
59
+ function handleFileDragOver(event: DragEvent) {
60
+ if (!isOsFileDrag(event)) return;
61
+ event.preventDefault();
62
+ if (event.dataTransfer) event.dataTransfer.dropEffect = 'copy';
63
+ isFileDragOver = true;
64
+ }
65
+
66
+ function handleFileDragLeave(event: DragEvent) {
67
+ if (!isOsFileDrag(event)) return;
68
+ const related = event.relatedTarget as Node | null;
69
+ if (related && (event.currentTarget as HTMLElement).contains(related)) return;
70
+ isFileDragOver = false;
71
+ }
72
+
73
+ function handleFileDrop(event: DragEvent) {
74
+ if (!isOsFileDrag(event)) return;
75
+ event.preventDefault();
76
+ event.stopPropagation();
77
+ isFileDragOver = false;
78
+ const droppedFiles = Array.from(event.dataTransfer?.files || []).filter(
79
+ (file) => file && file.size > 0,
80
+ );
81
+ if (droppedFiles.length === 0) return;
82
+ chatLog('[ChatInput] OS files dropped:', droppedFiles.length);
83
+ onFilesDropped?.(droppedFiles);
84
+ }
85
+
34
86
  let textArea: HTMLTextAreaElement;
35
87
 
36
88
  onMount(() => {
@@ -68,12 +120,23 @@
68
120
  if (attachment.preview) {
69
121
  return attachment.preview;
70
122
  }
123
+ if (!attachment.file) {
124
+ return '';
125
+ }
71
126
  const objectUrl = URL.createObjectURL(attachment.file);
72
127
  createdObjectUrls.add(objectUrl);
73
128
  attachment.preview = objectUrl;
74
129
  return objectUrl;
75
130
  }
76
131
 
132
+ function isImageAttachment(attachment: AttachmentInput): boolean {
133
+ return (
134
+ attachment.type === 'image' ||
135
+ !!attachment.file?.type?.startsWith('image/') ||
136
+ !!attachment.preview
137
+ );
138
+ }
139
+
77
140
  function removeAttachment(index: number) {
78
141
  const removed = attachments[index];
79
142
  if (removed?.preview && removed.preview.startsWith('blob:')) {
@@ -110,11 +173,14 @@
110
173
  }
111
174
 
112
175
  function handleAttachmentDragOver(e: DragEvent) {
176
+ // Do not hijack OS file drops — those are handled on the input container.
177
+ if (isOsFileDrag(e)) return;
113
178
  e.preventDefault();
114
179
  if (e.dataTransfer) e.dataTransfer.dropEffect = 'move';
115
180
  }
116
181
 
117
182
  function handleAttachmentDrop(targetIndex: number, e: DragEvent) {
183
+ if (isOsFileDrag(e)) return;
118
184
  e.preventDefault();
119
185
  if (draggingAttachmentIndex === null || draggingAttachmentIndex === targetIndex) {
120
186
  draggingAttachmentIndex = null;
@@ -173,11 +239,20 @@
173
239
  });
174
240
  </script>
175
241
 
176
- <div class="chat-input-ct border-t border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-800">
177
- <!-- Attachments Preview -->
178
- {#if attachments.length > 0}
242
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
243
+ <div
244
+ class="chat-input-ct border-t border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-800 transition-colors {className}
245
+ {isFileDragOver ? 'chat-input-file-drag-over border-2 border-dashed border-blue-400 bg-blue-50/70 dark:bg-blue-900/20' : ''}"
246
+ {style}
247
+ ondragenter={handleFileDragEnter}
248
+ ondragover={handleFileDragOver}
249
+ ondragleave={handleFileDragLeave}
250
+ ondrop={handleFileDrop}
251
+ >
252
+ <!-- Attachments Preview (skipped when parent owns the footer tray) -->
253
+ {#if showAttachmentsTray && attachments.length > 0}
179
254
  <div class="attachments-preview-ct flex flex-wrap gap-2 p-3 border-b border-gray-100 dark:border-gray-700">
180
- {#each attachments as attachment, index}
255
+ {#each attachments as attachment, index (attachment.preview || attachment.file?.name || index)}
181
256
  <!-- svelte-ignore a11y_no_static_element_interactions -->
182
257
  <div
183
258
  class="attachment-preview-item-ct relative bg-gray-50 dark:bg-gray-700 rounded-lg overflow-hidden"
@@ -188,12 +263,12 @@
188
263
  ondragend={handleAttachmentDragEnd}
189
264
  >
190
265
  <span class="attachment-index-badge absolute top-0.5 left-0.5 z-10 w-4 h-4 flex items-center justify-center rounded-full bg-blue-600 text-white text-[9px] font-bold shadow">{index + 1}</span>
191
- {#if attachment.file.type.startsWith('image/')}
266
+ {#if isImageAttachment(attachment)}
192
267
  <!-- svelte-ignore a11y_click_events_have_key_events -->
193
268
  <!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
194
269
  <img
195
270
  src={getAttachmentPreviewUrl(attachment)}
196
- alt={attachment.file.name}
271
+ alt={attachment.file?.name || 'attachment'}
197
272
  class="image-preview-ct w-16 h-16 object-cover cursor-pointer"
198
273
  onclick={() => openLightbox(attachment)}
199
274
  />
@@ -201,13 +276,13 @@
201
276
  <!-- File Preview -->
202
277
  <div class="file-preview-ct flex items-center gap-2 p-3 w-32">
203
278
  <span class="text-lg">📄</span>
204
- <span class="text-xs text-gray-600 dark:text-gray-300 truncate flex-1">{attachment.file.name}</span>
279
+ <span class="text-xs text-gray-600 dark:text-gray-300 truncate flex-1">{attachment.file?.name || 'attachment'}</span>
205
280
  </div>
206
281
  {/if}
207
282
 
208
283
  <!-- Remove Button -->
209
284
  <button
210
- class="absolute top-1 right-1 w-5 h-5 bg-red-500 text-white rounded-full flex items-center justify-center text-xs hover:bg-red-600"
285
+ class="remove-attachment-btn absolute top-1 right-1 w-5 h-5 bg-red-500 text-white rounded-full flex items-center justify-center text-xs hover:bg-red-600 cursor-pointer"
211
286
  onclick={() => removeAttachment(index)}
212
287
  aria-label="Remove attachment"
213
288
  >
@@ -6,11 +6,20 @@ interface Props {
6
6
  isSending: boolean;
7
7
  isUploading: boolean;
8
8
  isGenerating?: boolean;
9
+ /**
10
+ * When false, skip the in-input attachments tray (parent renders it in the chat footer).
11
+ * Drag-drop on `.chat-input-ct` still works.
12
+ */
13
+ showAttachmentsTray?: boolean;
9
14
  onSend: (content: string, attachments?: AttachmentInput[]) => void;
10
15
  onStop?: () => void;
11
16
  onInputChange: (text: string) => void;
12
17
  onAttachmentsChange: (attachments: AttachmentInput[]) => void;
18
+ /** OS file drag-and-drop onto the input area (not attachment reorder). */
19
+ onFilesDropped?: (files: File[]) => void;
13
20
  placeholder?: string;
21
+ class?: string;
22
+ style?: string;
14
23
  }
15
24
  declare const ChatInput: import("svelte").Component<Props, {}, "">;
16
25
  type ChatInput = ReturnType<typeof ChatInput>;
@@ -30,6 +30,10 @@
30
30
  showGenerationSummaries?: boolean;
31
31
  /** Host widget HEAD sha — Head chrome when assistant commit bubbles are missing. */
32
32
  widgetHeadCommitSha?: string | null;
33
+ /** When false, hide commit hashes next to Head-at-commit (user mode). */
34
+ showCommitMeta?: boolean;
35
+ /** True while codegen / send is in flight — suppresses premature Retry. */
36
+ isGenerating?: boolean;
33
37
  onSuggestionSelected?: (suggestion: string) => void;
34
38
  onRestoreCheckpoint?: (messageId: string, messageIndex: number) => void;
35
39
  onRetryMessage?: (content: string) => void;
@@ -44,6 +48,8 @@
44
48
  enableAutoCodeDetection = false,
45
49
  showGenerationSummaries = false,
46
50
  widgetHeadCommitSha = null,
51
+ showCommitMeta = true,
52
+ isGenerating = false,
47
53
  onSuggestionSelected,
48
54
  onRestoreCheckpoint,
49
55
  onRetryMessage,
@@ -388,6 +394,8 @@
388
394
  }
389
395
 
390
396
  function turnNeedsRetry(turn: ChatTurn): boolean {
397
+ // Never show Retry while a send/codegen is still running.
398
+ if (isLoading || isGenerating) return false;
391
399
  if (turnHasCodegenFailure(turn)) return true;
392
400
  const userMsg = turn.user;
393
401
  if (!userMsg?.messageContent) return false;
@@ -395,11 +403,10 @@
395
403
  if (noAttachments && messageImpliesAttachedFile(userMsg.messageContent) && !getTurnCommitReply(turn)) {
396
404
  return true;
397
405
  }
398
- // Stopped / incomplete last prompt: progress bubbles are hidden when Debug is off.
399
- return isLastUserTurn(turn)
400
- && !isLoading
401
- && !getTurnCommitReply(turn)
402
- && !getFallbackHeadReply(turn);
406
+ // Stopped / incomplete last prompt only — not mid-flight before the first assistant reply.
407
+ // Incomplete without failure/stop is handled by the host via lastGenerationFailed /
408
+ // "Generation stopped by user" assistant text (turnHasCodegenFailure).
409
+ return false;
403
410
  }
404
411
 
405
412
  let visibleMessages = $derived(
@@ -860,7 +867,7 @@
860
867
  Head at commit
861
868
  </div>
862
869
  {/if}
863
- {#if getTurnCommitShort(turn)}
870
+ {#if showCommitMeta && getTurnCommitShort(turn)}
864
871
  <span class="wc-user-commit-sha font-mono text-xs text-gray-500">
865
872
  Commit {getTurnCommitShort(turn)}
866
873
  </span>
@@ -21,6 +21,10 @@ interface Props {
21
21
  showGenerationSummaries?: boolean;
22
22
  /** Host widget HEAD sha — Head chrome when assistant commit bubbles are missing. */
23
23
  widgetHeadCommitSha?: string | null;
24
+ /** When false, hide commit hashes next to Head-at-commit (user mode). */
25
+ showCommitMeta?: boolean;
26
+ /** True while codegen / send is in flight — suppresses premature Retry. */
27
+ isGenerating?: boolean;
24
28
  onSuggestionSelected?: (suggestion: string) => void;
25
29
  onRestoreCheckpoint?: (messageId: string, messageIndex: number) => void;
26
30
  onRetryMessage?: (content: string) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/chat",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",