@widgetic/chat 0.1.34 → 0.1.35

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.
@@ -281,6 +281,8 @@
281
281
  // Local state
282
282
  let chatContainer: HTMLElement;
283
283
  let isInitialized = $state(false);
284
+ /** Suggestions stay hidden from the first paint. Turned on only after the message read, and only when it was empty. */
285
+ let showEmptyState = $state(false);
284
286
  let chatService = $state(createChatService());
285
287
  let currentConversationId = $state<string | null>(null);
286
288
 
@@ -452,27 +454,43 @@
452
454
  }
453
455
 
454
456
  let lastLoadedContextId = $state('');
457
+ let contextInitToken = 0;
455
458
 
456
459
  async function initializeForContext(contextId: string) {
457
460
  if (!contextId) return;
461
+ const token = ++contextInitToken;
458
462
  lastLoadedContextId = contextId;
459
- // chatLog('[Chat] Initializing with context:', contextId);
460
- chatStore.actions.setActiveContext(contextId, true);
463
+ // Hidden until this read finishes, so suggestion chips do not flash over a conversation that has messages.
464
+ isInitialized = false;
465
+ showEmptyState = false;
466
+ let conversationWasRead = false;
467
+ try {
468
+ // chatLog('[Chat] Initializing with context:', contextId);
469
+ chatStore.actions.setActiveContext(contextId, true);
461
470
 
462
- const loaded = await loadConversations();
463
- if (loaded === null) {
464
- showLoadFailure('chat.error.loadHistory');
465
- return;
466
- }
471
+ const loaded = await loadConversations();
472
+ if (token !== contextInitToken) return;
473
+ if (loaded === null) {
474
+ showLoadFailure('chat.error.loadHistory');
475
+ return;
476
+ }
467
477
 
468
- if (loaded.length === 0) {
469
- // chatLog('[Chat] No existing conversations, creating new one');
470
- await createNewConversation();
471
- } else {
472
- // chatLog('[Chat] Selecting from', loaded.length, 'conversation(s)');
473
- await activateBestConversation(loaded);
478
+ if (loaded.length === 0) {
479
+ // chatLog('[Chat] No existing conversations, creating new one');
480
+ await createNewConversation();
481
+ } else {
482
+ // chatLog('[Chat] Selecting from', loaded.length, 'conversation(s)');
483
+ await activateBestConversation(loaded);
484
+ }
485
+ conversationWasRead = true;
486
+ // chatLog('[Chat] Initialized successfully');
487
+ } finally {
488
+ if (token !== contextInitToken) return;
489
+ const loadedMessages = currentConversationId ? (getCurrentMessages(currentConversationId) ?? []) : [];
490
+ // Only the read that just finished may show suggestions, and only when it stored no messages.
491
+ showEmptyState = conversationWasRead && loadedMessages.length === 0;
492
+ isInitialized = true;
474
493
  }
475
- // chatLog('[Chat] Initialized successfully');
476
494
  }
477
495
 
478
496
  async function retryLoadHistory() {
@@ -1680,6 +1698,8 @@
1680
1698
  /** Reload messages from backend and re-mark widget HEAD (picks up server-persisted summaries). */
1681
1699
  async function reloadConversationMessages() {
1682
1700
  if (!currentConversationId || !onLoadMessages) return;
1701
+ const conversationId = currentConversationId;
1702
+ showEmptyState = false;
1683
1703
  try {
1684
1704
  const localMsgs = getCurrentMessages(currentConversationId);
1685
1705
  const localHasHead = localMsgs.some((m) => m.isWidgetHead || messageHasWidgetCommit(m.messageContent));
@@ -1713,6 +1733,10 @@
1713
1733
  // chatLog('[Chat] Reloaded conversation messages:', loaded?.length ?? 0);
1714
1734
  } catch (err) {
1715
1735
  chatWarn('[Chat] Failed to reload conversation messages:', err);
1736
+ } finally {
1737
+ if (currentConversationId !== conversationId) return;
1738
+ const loadedCount = getCurrentMessages(conversationId)?.length ?? 0;
1739
+ showEmptyState = loadedCount === 0;
1716
1740
  }
1717
1741
  }
1718
1742
 
@@ -1939,6 +1963,7 @@
1939
1963
  messages={currentMessages || []}
1940
1964
  isLoading={isLoading}
1941
1965
  isInitialized={isInitialized}
1966
+ {showEmptyState}
1942
1967
  {context}
1943
1968
  isCompleted={isCompleted}
1944
1969
  enableAutoCodeDetection={config?.features?.autoCodeDetection === true}
@@ -23,8 +23,13 @@
23
23
  class?: string;
24
24
  messages: ChatMessage[];
25
25
  isLoading?: boolean;
26
- /** True after the conversation list/messages finished initializing — gates the empty state so suggestions never flash at mount. */
26
+ /** True after the conversation list/messages finished initializing. */
27
27
  isInitialized?: boolean;
28
+ /**
29
+ * The empty-state suggestions. Stays false from the first paint.
30
+ * The parent sets it only after the message read, and only when that read was empty.
31
+ */
32
+ showEmptyState?: boolean;
28
33
  context: ChatContext;
29
34
  isCompleted?: boolean;
30
35
  /**
@@ -99,7 +104,8 @@
99
104
  class: className = '',
100
105
  messages,
101
106
  isLoading = false,
102
- isInitialized = true,
107
+ isInitialized = false,
108
+ showEmptyState = false,
103
109
  context,
104
110
  isCompleted = false,
105
111
  enableAutoCodeDetection = false,
@@ -1457,11 +1463,10 @@
1457
1463
  use:detectMessagesScrollbar
1458
1464
  onscroll={handleScroll}
1459
1465
  >
1460
- <!-- Empty state with suggestions — hidden until initialization completes so
1461
- suggestions never flash before the loaded messages arrive, and hidden
1462
- while a generation is in flight (the optimistic user bubble lands a tick
1463
- after send, so the list is briefly empty again). -->
1464
- {#if isInitialized && messages.length === 0 && !isLoading && !isGenerating}
1466
+ <!-- Empty state stays out of the document until the parent has finished reading
1467
+ messages and found none. A generation in flight hides it too: the user
1468
+ bubble lands a tick after send, so the list is briefly empty again. -->
1469
+ {#if showEmptyState && !isLoading && !isGenerating}
1465
1470
  <div class="empty-state-ct flex flex-col items-center justify-center text-center max-w-sm w-full" style="align-self: center;">
1466
1471
  <h3 class="text-lg font-semibold text-gray-900 dark:text-gray-100 mb-2">💬 {$t('chat.messages.startTitle')}</h3>
1467
1472
  <p class="text-gray-600 dark:text-gray-400 text-sm mb-6">
@@ -6,8 +6,13 @@ interface Props {
6
6
  class?: string;
7
7
  messages: ChatMessage[];
8
8
  isLoading?: boolean;
9
- /** True after the conversation list/messages finished initializing — gates the empty state so suggestions never flash at mount. */
9
+ /** True after the conversation list/messages finished initializing. */
10
10
  isInitialized?: boolean;
11
+ /**
12
+ * The empty-state suggestions. Stays false from the first paint.
13
+ * The parent sets it only after the message read, and only when that read was empty.
14
+ */
15
+ showEmptyState?: boolean;
11
16
  context: ChatContext;
12
17
  isCompleted?: boolean;
13
18
  /**
@@ -3,17 +3,17 @@ import { type MessageOverrides, type MessageProblem } from '@widgetic/design-sys
3
3
  * Called by the root component of a chat while it is created, so everything inside it speaks the page's language.
4
4
  * It gives back the words as stores and `update(settings)` for when the page sets the language again.
5
5
  */
6
- export declare const provideChatLanguage: (initial: import("@widgetic/design-system/i18n").I18nSettings) => import("@widgetic/design-system/i18n").I18nHandle<"chat.contextType.frame" | "chat.contextType.text" | "chat.contextType.image" | "chat.contextType.document" | "chat.contextType.canvas" | "chat.header.typeChat" | "chat.header.switchConversation" | "chat.header.conversations" | "chat.header.new" | "chat.header.untitled" | "chat.header.newConversationTitle" | "chat.header.newConversation" | "chat.header.close" | "chat.contextPreview.expand" | "chat.conversation.defaultTitle" | "chat.messages.startTitle" | "chat.messages.startHint" | "chat.messages.loadingHistory" | "chat.messages.thinking" | "chat.messages.viewing" | "chat.messages.viewingTitle" | "chat.messages.attachmentMissingTitle" | "chat.messages.attachmentMissingLabel" | "chat.messages.attachmentMissingCaption" | "chat.messages.retry" | "chat.messages.retryPromptTitle" | "chat.messages.retryLastTitle" | "chat.messages.upgrade" | "chat.messages.upgradeTitle" | "chat.messages.commitId" | "chat.messages.restore" | "chat.messages.restoreTitle" | "chat.messages.alreadyHead" | "chat.messages.rateGroup" | "chat.messages.rateUp" | "chat.messages.rateDown" | "chat.messages.version" | "chat.messages.restoredFrom" | "chat.messages.previousVersion" | "chat.suggestions.title.frame" | "chat.suggestions.title.text" | "chat.suggestions.title.image" | "chat.suggestions.title.document" | "chat.suggestions.title.other" | "chat.suggestions.hide" | "chat.suggestions.frame.generateCode" | "chat.suggestions.frame.improveLayout" | "chat.suggestions.frame.addInteractivity" | "chat.suggestions.frame.makeResponsive" | "chat.suggestions.frame.addAnimations" | "chat.suggestions.text.improveWriting" | "chat.suggestions.text.checkGrammar" | "chat.suggestions.text.alternativePhrasing" | "chat.suggestions.text.summarize" | "chat.suggestions.text.expand" | "chat.suggestions.image.describe" | "chat.suggestions.image.altText" | "chat.suggestions.image.improveDesign" | "chat.suggestions.image.toCode" | "chat.suggestions.image.extractText" | "chat.suggestions.document.summarize" | "chat.suggestions.document.keyPoints" | "chat.suggestions.document.checkErrors" | "chat.suggestions.document.improve" | "chat.suggestions.document.outline" | "chat.suggestions.other.ask" | "chat.suggestions.other.improve" | "chat.suggestions.other.explain" | "chat.suggestions.other.understand" | "chat.suggestions.other.options" | "chat.input.placeholder" | "chat.input.stop" | "chat.input.sending" | "chat.input.send" | "chat.actions.screenshot" | "chat.actions.screenshotTitle" | "chat.actions.screenshotLabel" | "chat.actions.record" | "chat.actions.stop" | "chat.actions.startRecordingTitle" | "chat.actions.stopRecordingTitle" | "chat.actions.startRecordingLabel" | "chat.actions.stopRecordingLabel" | "chat.actions.upload" | "chat.actions.uploadTitle" | "chat.actions.uploadLabel" | "chat.actions.selector" | "chat.actions.selectorTitle" | "chat.actions.selectorActiveTitle" | "chat.actions.selectorLabel" | "chat.selector.removeElement" | "chat.selector.clearAll" | "chat.actions.complete" | "chat.actions.completed" | "chat.actions.markCompleteTitle" | "chat.actions.markActiveTitle" | "chat.actions.markCompleteLabel" | "chat.actions.markActiveLabel" | "chat.resize.label" | "chat.resize.title" | "chat.attachment.alt" | "chat.attachment.untitled" | "chat.attachment.fileFallback" | "chat.attachment.namelessAlt" | "chat.attachment.previewAlt" | "chat.attachment.pdfTitle" | "chat.attachment.noVideo" | "chat.attachment.view" | "chat.attachment.viewFile" | "chat.attachment.more" | "chat.attachment.remove" | "chat.attachment.close" | "chat.size.bytes" | "chat.size.kb" | "chat.size.mb" | "chat.size.gb" | "chat.code.copy" | "chat.code.copyTitle" | "chat.code.copied" | "chat.status.active" | "chat.status.completed" | "chat.status.processing" | "chat.status.error" | "chat.status.messageCount" | "chat.error.dismiss" | "chat.error.retryLoad" | "chat.error.loadHistory" | "chat.error.initialize" | "chat.error.loadConversations" | "chat.error.loadConversation" | "chat.error.sendMessage" | "chat.error.sendSuggestion" | "chat.error.screenshotUnavailable" | "chat.error.screenshotFailed" | "chat.error.screenshotActionFailed" | "chat.error.recordingStartFailed" | "chat.error.recordingStopFailed" | "chat.error.recordingActionFailed" | "chat.error.actionFailed" | "chat.error.statusUpdateFailed" | "chat.error.restoreFailed">;
6
+ export declare const provideChatLanguage: any;
7
7
  /**
8
8
  * Called by a part of the chat while it is created. Gives its words as stores, so a part that is already on the screen
9
9
  * changes when the page sets the language again. Outside a chat (a part used on its own) it speaks English.
10
10
  */
11
- export declare const useChatLanguage: () => import("@widgetic/design-system/i18n").I18nContext<"chat.contextType.frame" | "chat.contextType.text" | "chat.contextType.image" | "chat.contextType.document" | "chat.contextType.canvas" | "chat.header.typeChat" | "chat.header.switchConversation" | "chat.header.conversations" | "chat.header.new" | "chat.header.untitled" | "chat.header.newConversationTitle" | "chat.header.newConversation" | "chat.header.close" | "chat.contextPreview.expand" | "chat.conversation.defaultTitle" | "chat.messages.startTitle" | "chat.messages.startHint" | "chat.messages.loadingHistory" | "chat.messages.thinking" | "chat.messages.viewing" | "chat.messages.viewingTitle" | "chat.messages.attachmentMissingTitle" | "chat.messages.attachmentMissingLabel" | "chat.messages.attachmentMissingCaption" | "chat.messages.retry" | "chat.messages.retryPromptTitle" | "chat.messages.retryLastTitle" | "chat.messages.upgrade" | "chat.messages.upgradeTitle" | "chat.messages.commitId" | "chat.messages.restore" | "chat.messages.restoreTitle" | "chat.messages.alreadyHead" | "chat.messages.rateGroup" | "chat.messages.rateUp" | "chat.messages.rateDown" | "chat.messages.version" | "chat.messages.restoredFrom" | "chat.messages.previousVersion" | "chat.suggestions.title.frame" | "chat.suggestions.title.text" | "chat.suggestions.title.image" | "chat.suggestions.title.document" | "chat.suggestions.title.other" | "chat.suggestions.hide" | "chat.suggestions.frame.generateCode" | "chat.suggestions.frame.improveLayout" | "chat.suggestions.frame.addInteractivity" | "chat.suggestions.frame.makeResponsive" | "chat.suggestions.frame.addAnimations" | "chat.suggestions.text.improveWriting" | "chat.suggestions.text.checkGrammar" | "chat.suggestions.text.alternativePhrasing" | "chat.suggestions.text.summarize" | "chat.suggestions.text.expand" | "chat.suggestions.image.describe" | "chat.suggestions.image.altText" | "chat.suggestions.image.improveDesign" | "chat.suggestions.image.toCode" | "chat.suggestions.image.extractText" | "chat.suggestions.document.summarize" | "chat.suggestions.document.keyPoints" | "chat.suggestions.document.checkErrors" | "chat.suggestions.document.improve" | "chat.suggestions.document.outline" | "chat.suggestions.other.ask" | "chat.suggestions.other.improve" | "chat.suggestions.other.explain" | "chat.suggestions.other.understand" | "chat.suggestions.other.options" | "chat.input.placeholder" | "chat.input.stop" | "chat.input.sending" | "chat.input.send" | "chat.actions.screenshot" | "chat.actions.screenshotTitle" | "chat.actions.screenshotLabel" | "chat.actions.record" | "chat.actions.stop" | "chat.actions.startRecordingTitle" | "chat.actions.stopRecordingTitle" | "chat.actions.startRecordingLabel" | "chat.actions.stopRecordingLabel" | "chat.actions.upload" | "chat.actions.uploadTitle" | "chat.actions.uploadLabel" | "chat.actions.selector" | "chat.actions.selectorTitle" | "chat.actions.selectorActiveTitle" | "chat.actions.selectorLabel" | "chat.selector.removeElement" | "chat.selector.clearAll" | "chat.actions.complete" | "chat.actions.completed" | "chat.actions.markCompleteTitle" | "chat.actions.markActiveTitle" | "chat.actions.markCompleteLabel" | "chat.actions.markActiveLabel" | "chat.resize.label" | "chat.resize.title" | "chat.attachment.alt" | "chat.attachment.untitled" | "chat.attachment.fileFallback" | "chat.attachment.namelessAlt" | "chat.attachment.previewAlt" | "chat.attachment.pdfTitle" | "chat.attachment.noVideo" | "chat.attachment.view" | "chat.attachment.viewFile" | "chat.attachment.more" | "chat.attachment.remove" | "chat.attachment.close" | "chat.size.bytes" | "chat.size.kb" | "chat.size.mb" | "chat.size.gb" | "chat.code.copy" | "chat.code.copyTitle" | "chat.code.copied" | "chat.status.active" | "chat.status.completed" | "chat.status.processing" | "chat.status.error" | "chat.status.messageCount" | "chat.error.dismiss" | "chat.error.retryLoad" | "chat.error.loadHistory" | "chat.error.initialize" | "chat.error.loadConversations" | "chat.error.loadConversation" | "chat.error.sendMessage" | "chat.error.sendSuggestion" | "chat.error.screenshotUnavailable" | "chat.error.screenshotFailed" | "chat.error.screenshotActionFailed" | "chat.error.recordingStartFailed" | "chat.error.recordingStopFailed" | "chat.error.recordingActionFailed" | "chat.error.actionFailed" | "chat.error.statusUpdateFailed" | "chat.error.restoreFailed">;
11
+ export declare const useChatLanguage: any;
12
12
  /**
13
13
  * The English `t` of the chat, for code that has no component around it. The screens of the chat get their words, in the
14
14
  * page's language, from `useChatLanguage`.
15
15
  */
16
- export declare const translateEnglish: import("@widgetic/design-system/i18n").Translate<"chat.contextType.frame" | "chat.contextType.text" | "chat.contextType.image" | "chat.contextType.document" | "chat.contextType.canvas" | "chat.header.typeChat" | "chat.header.switchConversation" | "chat.header.conversations" | "chat.header.new" | "chat.header.untitled" | "chat.header.newConversationTitle" | "chat.header.newConversation" | "chat.header.close" | "chat.contextPreview.expand" | "chat.conversation.defaultTitle" | "chat.messages.startTitle" | "chat.messages.startHint" | "chat.messages.loadingHistory" | "chat.messages.thinking" | "chat.messages.viewing" | "chat.messages.viewingTitle" | "chat.messages.attachmentMissingTitle" | "chat.messages.attachmentMissingLabel" | "chat.messages.attachmentMissingCaption" | "chat.messages.retry" | "chat.messages.retryPromptTitle" | "chat.messages.retryLastTitle" | "chat.messages.upgrade" | "chat.messages.upgradeTitle" | "chat.messages.commitId" | "chat.messages.restore" | "chat.messages.restoreTitle" | "chat.messages.alreadyHead" | "chat.messages.rateGroup" | "chat.messages.rateUp" | "chat.messages.rateDown" | "chat.messages.version" | "chat.messages.restoredFrom" | "chat.messages.previousVersion" | "chat.suggestions.title.frame" | "chat.suggestions.title.text" | "chat.suggestions.title.image" | "chat.suggestions.title.document" | "chat.suggestions.title.other" | "chat.suggestions.hide" | "chat.suggestions.frame.generateCode" | "chat.suggestions.frame.improveLayout" | "chat.suggestions.frame.addInteractivity" | "chat.suggestions.frame.makeResponsive" | "chat.suggestions.frame.addAnimations" | "chat.suggestions.text.improveWriting" | "chat.suggestions.text.checkGrammar" | "chat.suggestions.text.alternativePhrasing" | "chat.suggestions.text.summarize" | "chat.suggestions.text.expand" | "chat.suggestions.image.describe" | "chat.suggestions.image.altText" | "chat.suggestions.image.improveDesign" | "chat.suggestions.image.toCode" | "chat.suggestions.image.extractText" | "chat.suggestions.document.summarize" | "chat.suggestions.document.keyPoints" | "chat.suggestions.document.checkErrors" | "chat.suggestions.document.improve" | "chat.suggestions.document.outline" | "chat.suggestions.other.ask" | "chat.suggestions.other.improve" | "chat.suggestions.other.explain" | "chat.suggestions.other.understand" | "chat.suggestions.other.options" | "chat.input.placeholder" | "chat.input.stop" | "chat.input.sending" | "chat.input.send" | "chat.actions.screenshot" | "chat.actions.screenshotTitle" | "chat.actions.screenshotLabel" | "chat.actions.record" | "chat.actions.stop" | "chat.actions.startRecordingTitle" | "chat.actions.stopRecordingTitle" | "chat.actions.startRecordingLabel" | "chat.actions.stopRecordingLabel" | "chat.actions.upload" | "chat.actions.uploadTitle" | "chat.actions.uploadLabel" | "chat.actions.selector" | "chat.actions.selectorTitle" | "chat.actions.selectorActiveTitle" | "chat.actions.selectorLabel" | "chat.selector.removeElement" | "chat.selector.clearAll" | "chat.actions.complete" | "chat.actions.completed" | "chat.actions.markCompleteTitle" | "chat.actions.markActiveTitle" | "chat.actions.markCompleteLabel" | "chat.actions.markActiveLabel" | "chat.resize.label" | "chat.resize.title" | "chat.attachment.alt" | "chat.attachment.untitled" | "chat.attachment.fileFallback" | "chat.attachment.namelessAlt" | "chat.attachment.previewAlt" | "chat.attachment.pdfTitle" | "chat.attachment.noVideo" | "chat.attachment.view" | "chat.attachment.viewFile" | "chat.attachment.more" | "chat.attachment.remove" | "chat.attachment.close" | "chat.size.bytes" | "chat.size.kb" | "chat.size.mb" | "chat.size.gb" | "chat.code.copy" | "chat.code.copyTitle" | "chat.code.copied" | "chat.status.active" | "chat.status.completed" | "chat.status.processing" | "chat.status.error" | "chat.status.messageCount" | "chat.error.dismiss" | "chat.error.retryLoad" | "chat.error.loadHistory" | "chat.error.initialize" | "chat.error.loadConversations" | "chat.error.loadConversation" | "chat.error.sendMessage" | "chat.error.sendSuggestion" | "chat.error.screenshotUnavailable" | "chat.error.screenshotFailed" | "chat.error.screenshotActionFailed" | "chat.error.recordingStartFailed" | "chat.error.recordingStopFailed" | "chat.error.recordingActionFailed" | "chat.error.actionFailed" | "chat.error.statusUpdateFailed" | "chat.error.restoreFailed">;
16
+ export declare const translateEnglish: any;
17
17
  /**
18
18
  * Checks a page's `messages` against the chat's catalog without showing anything: a key that does not exist (with the
19
19
  * nearest real one), a value that is not text, a template that does not parse, or one that asks for a value the message
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/chat",
3
- "version": "0.1.34",
3
+ "version": "0.1.35",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",