@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
|
-
//
|
|
460
|
-
|
|
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
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
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
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
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
|
|
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 =
|
|
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
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
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
|
|
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
|
/**
|
package/dist/i18n/language.d.ts
CHANGED
|
@@ -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:
|
|
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:
|
|
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:
|
|
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
|