@widgetic/chat 0.1.32 → 0.1.34
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/README.md +34 -0
- package/dist/components/Chat.svelte +61 -4
- package/dist/components/Chat.svelte.d.ts +13 -1
- package/dist/components/ChatInput.svelte +11 -4
- package/dist/components/ChatInput.svelte.d.ts +2 -0
- package/dist/components/ChatMessages.svelte +97 -4
- package/dist/components/ChatMessages.svelte.d.ts +9 -1
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +4 -0
- package/dist/i18n/messages.js +4 -0
- package/dist/types/attachment.d.ts +2 -0
- package/dist/types/message.d.ts +6 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/versionRatings.d.ts +28 -0
- package/dist/utils/versionRatings.js +41 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -161,6 +161,40 @@ You can also use individual components:
|
|
|
161
161
|
/>
|
|
162
162
|
```
|
|
163
163
|
|
|
164
|
+
### Rating a version
|
|
165
|
+
|
|
166
|
+
Next to the name of each version (the reply that announced a change of the widget) the chat can draw two thumbs, so a person can say whether
|
|
167
|
+
that version is good. The thumbs are **opt-in**: give `Chat` an `onRateVersion` callback and they appear, leave it out and the chat looks and
|
|
168
|
+
works as it always did. The chat keeps no rating of its own: the page decides where a rating goes. A rating is one of three words: `up`,
|
|
169
|
+
`down`, or `none` (the person took their rating back).
|
|
170
|
+
|
|
171
|
+
```svelte
|
|
172
|
+
<script lang="ts">
|
|
173
|
+
import { Chat, type VersionRating } from '@widgetic/chat';
|
|
174
|
+
|
|
175
|
+
// What the page already knows: message id -> rating (optional, see below)
|
|
176
|
+
let ratingsKeptByThePage: Record<string, VersionRating> = {};
|
|
177
|
+
|
|
178
|
+
async function rateVersion(conversationId: string, messageId: string, rating: VersionRating) {
|
|
179
|
+
// Throw when the rating was not kept: the chat puts the thumb back as it was.
|
|
180
|
+
await api.rateMessageVersion({ conversationId, messageId, rateMessageVersionRequest: { rating } });
|
|
181
|
+
}
|
|
182
|
+
</script>
|
|
183
|
+
|
|
184
|
+
<Chat {context} onRateVersion={rateVersion} versionRatings={ratingsKeptByThePage} />
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
- `onRateVersion(conversationId, messageId, rating)` is called with the id of the saved message that announced the version and the rating the
|
|
188
|
+
version has **now**. Pressing the thumb that is already chosen takes the rating back, and the callback then receives `none`.
|
|
189
|
+
- The chat shows the press at once. When the callback throws or rejects, the thumb goes back to what it was; while a call for a version is
|
|
190
|
+
still on its way, a second press on that version is ignored, so two answers cannot arrive in the wrong order.
|
|
191
|
+
- `versionRatings` (optional) is a record of `messageId` to rating, for a page that keeps ratings and gives them back when the chat opens
|
|
192
|
+
again. What the person pressed in this chat is shown over it. Without it, the thumbs start empty each time the chat opens.
|
|
193
|
+
- Only a version the backend saved can be rated: not a reply still on its way or one that failed, not the copy a restore appends, not the
|
|
194
|
+
stand-in the chat draws while the widget's head is ahead of every saved message, and not a version a restore undid. Nothing is drawn while
|
|
195
|
+
the chat is loading.
|
|
196
|
+
- Words: `chat.messages.rateGroup`, `chat.messages.rateUp` and `chat.messages.rateDown` (see [Languages](#languages)).
|
|
197
|
+
|
|
164
198
|
## State Management
|
|
165
199
|
|
|
166
200
|
The chat module uses Svelte 5 runes for reactive state management:
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
import { chatStore, getCurrentState, getCurrentMessages } from '../stores/chatStore.js';
|
|
7
7
|
import { createChatService } from '../services/chatService.js';
|
|
8
8
|
import { setLogsEnabled, chatLog, chatWarn } from '../utils/logger.js';
|
|
9
|
+
import { ratingAfterPress, ratingOfVersion, type VersionThumb } from '../utils/versionRatings.js';
|
|
9
10
|
import type { ChatConfig, ChatContext } from '../types/index.js';
|
|
10
|
-
import type { ClarificationSuggestion, DesignControlRequest } from '../types/message.js';
|
|
11
|
+
import type { ClarificationSuggestion, DesignControlRequest, VersionRating } from '../types/message.js';
|
|
11
12
|
import type { AttachmentInput, SelectedElementChatReference } from '../types/attachment.js';
|
|
12
13
|
import ChatMessages from './ChatMessages.svelte';
|
|
13
14
|
import ChatInput from './ChatInput.svelte';
|
|
@@ -80,6 +81,18 @@
|
|
|
80
81
|
designControls?: DesignControlRequest,
|
|
81
82
|
) => Promise<any>;
|
|
82
83
|
onRestoreCheckpointBackend?: (conversationId: string, checkpointMessageId: string) => Promise<any>;
|
|
84
|
+
/**
|
|
85
|
+
* Keeps the person's thumbs on a version: the assistant message that announced a commit of the widget. Called with the id of the
|
|
86
|
+
* conversation, the id of that message and `up`, `down` or `none` (the rating was taken back); the host sends it to its backend.
|
|
87
|
+
* The two thumbs are drawn next to a version's name only when this is given. Resolve when the rating is kept: a rejection puts the
|
|
88
|
+
* thumb back as it was. The rating is a hint for the host, so a host that cannot keep one should say nothing about it, not fail.
|
|
89
|
+
*/
|
|
90
|
+
onRateVersion?: (conversationId: string, messageId: string, rating: VersionRating) => Promise<unknown>;
|
|
91
|
+
/**
|
|
92
|
+
* The rating each version already has, by the id of the message that announced it, for a host that keeps ratings and gives them
|
|
93
|
+
* back when the chat opens again. What the person presses in this chat is read over it.
|
|
94
|
+
*/
|
|
95
|
+
versionRatings?: Record<string, VersionRating>;
|
|
83
96
|
onTakeScreenshot?: () => Promise<string | null>;
|
|
84
97
|
/** Fires whenever the active conversation ID changes (including initial null → uuid). */
|
|
85
98
|
onConversationChange?: (conversationId: string | null) => void;
|
|
@@ -218,7 +231,7 @@
|
|
|
218
231
|
updateLastUserMessageAttachments: (attachments: Array<{ id?: string; url: string; file_type?: string; file_name?: string | null }>) => void;
|
|
219
232
|
}
|
|
220
233
|
|
|
221
|
-
let { context, config = {}, class: className = '', locale = null, messages: languageMessages = null, dir = undefined, style = '', isCompleted = false, onStatsUpdate, onChatReady, onCompletionToggle, onSendMessage, onLoadConversations, onLoadMessages, onCreateConversation, onSaveMessage, onRestoreCheckpointBackend, onTakeScreenshot, onConversationChange, onDraftChange, onRetryMessage, onUpgradePlans, onUploadChatFile, showHeader = true, headerTitle = '', showDescriptionHeader = true, showLogs = true, resizeExpandsContainer = false, onMessagesResize, onMessagesDrag, onMessagesDragEnd, onLoadOlderMessages, widgetHeadCommitSha = null, versionLabelByCommitSha = {}, versionLabelByPrompt = {}, versionTimeline = [], viewingVersion = null, isGenerating = false, generationStream = '', onStopGeneration, renderDesignControls, actionBarExtras, completeReplacement, replaceComplete = false, showSelector = false, isSelectorActive = false, selectedElements = [], onToggleSelector, onRemoveSelectedElement, onClearSelectedElements, composerExtras, storedLineLabel }: Props = $props();
|
|
234
|
+
let { context, config = {}, class: className = '', locale = null, messages: languageMessages = null, dir = undefined, style = '', isCompleted = false, onStatsUpdate, onChatReady, onCompletionToggle, onSendMessage, onLoadConversations, onLoadMessages, onCreateConversation, onSaveMessage, onRestoreCheckpointBackend, onRateVersion, versionRatings: ratingsFromHost = {}, onTakeScreenshot, onConversationChange, onDraftChange, onRetryMessage, onUpgradePlans, onUploadChatFile, showHeader = true, headerTitle = '', showDescriptionHeader = true, showLogs = true, resizeExpandsContainer = false, onMessagesResize, onMessagesDrag, onMessagesDragEnd, onLoadOlderMessages, widgetHeadCommitSha = null, versionLabelByCommitSha = {}, versionLabelByPrompt = {}, versionTimeline = [], viewingVersion = null, isGenerating = false, generationStream = '', onStopGeneration, renderDesignControls, actionBarExtras, completeReplacement, replaceComplete = false, showSelector = false, isSelectorActive = false, selectedElements = [], onToggleSelector, onRemoveSelectedElement, onClearSelectedElements, composerExtras, storedLineLabel }: Props = $props();
|
|
222
235
|
|
|
223
236
|
// The words of everything inside the chat, in the language the page chose. The page can change the language while the
|
|
224
237
|
// chat is open: the settings are read again whenever they change (and setting the same language again does nothing).
|
|
@@ -635,7 +648,12 @@
|
|
|
635
648
|
});
|
|
636
649
|
|
|
637
650
|
// chatLog('[Chat] Sending message:', content.substring(0, 60));
|
|
638
|
-
const
|
|
651
|
+
const noteLines = (selectedElements ?? [])
|
|
652
|
+
.map((element) => element.note?.trim())
|
|
653
|
+
.filter((note): note is string => !!note);
|
|
654
|
+
const submittedContent = content.trim()
|
|
655
|
+
? content
|
|
656
|
+
: noteLines.join('\n');
|
|
639
657
|
const submittedAttachments = normalizedAttachments;
|
|
640
658
|
const submittedSelectedElements =
|
|
641
659
|
selectedElements && selectedElements.length > 0 ? [...selectedElements] : undefined;
|
|
@@ -1194,6 +1212,37 @@
|
|
|
1194
1212
|
?? null;
|
|
1195
1213
|
}
|
|
1196
1214
|
|
|
1215
|
+
/** What the person pressed in this chat, by the id of the message that announced the version: read over what the host gave. */
|
|
1216
|
+
let chosenVersionRatings = $state<Record<string, VersionRating>>({});
|
|
1217
|
+
/** The versions whose rating is on its way to the host: a press made meanwhile is ignored, so the thumbs and the host cannot disagree on which came last. */
|
|
1218
|
+
let versionRatingsInFlight = $state<Record<string, boolean>>({});
|
|
1219
|
+
|
|
1220
|
+
/** What each version's thumbs shows as pressed: the person's own press, else what the host knew. */
|
|
1221
|
+
const shownVersionRatings = $derived({ ...ratingsFromHost, ...chosenVersionRatings });
|
|
1222
|
+
|
|
1223
|
+
/** A thumb was pressed next to a version: the thumb answers at once, and goes back if the host could not keep the rating. */
|
|
1224
|
+
async function handleRateVersion(messageId: string, pressed: VersionThumb) {
|
|
1225
|
+
const conversationId = currentConversationId;
|
|
1226
|
+
if (!onRateVersion || !conversationId || !messageId) return;
|
|
1227
|
+
if (versionRatingsInFlight[messageId]) return;
|
|
1228
|
+
|
|
1229
|
+
const ratingBefore = ratingOfVersion(messageId, chosenVersionRatings, ratingsFromHost);
|
|
1230
|
+
const ratingAfter = ratingAfterPress(ratingBefore, pressed);
|
|
1231
|
+
chosenVersionRatings = { ...chosenVersionRatings, [messageId]: ratingAfter };
|
|
1232
|
+
versionRatingsInFlight = { ...versionRatingsInFlight, [messageId]: true };
|
|
1233
|
+
try {
|
|
1234
|
+
await onRateVersion(conversationId, messageId, ratingAfter);
|
|
1235
|
+
chatLog('[Chat] Version rated:', { messageId, rating: ratingAfter });
|
|
1236
|
+
} catch (error) {
|
|
1237
|
+
chosenVersionRatings = { ...chosenVersionRatings, [messageId]: ratingBefore };
|
|
1238
|
+
chatWarn('[Chat] The rating of a version could not be kept:', error);
|
|
1239
|
+
} finally {
|
|
1240
|
+
const stillInFlight = { ...versionRatingsInFlight };
|
|
1241
|
+
delete stillInFlight[messageId];
|
|
1242
|
+
versionRatingsInFlight = stillInFlight;
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1197
1246
|
async function handleRestoreCheckpoint(messageId: string, messageIndex: number) {
|
|
1198
1247
|
// chatLog('Restore checkpoint requested:', { messageId, messageIndex, conversationId: currentConversationId });
|
|
1199
1248
|
|
|
@@ -1906,6 +1955,8 @@
|
|
|
1906
1955
|
generationStream={isGenerating ? generationStream : ''}
|
|
1907
1956
|
onSuggestionSelected={handleSuggestionSelected}
|
|
1908
1957
|
onRestoreCheckpoint={handleRestoreCheckpoint}
|
|
1958
|
+
onRateVersion={onRateVersion ? handleRateVersion : undefined}
|
|
1959
|
+
versionRatings={shownVersionRatings}
|
|
1909
1960
|
onRetryMessage={handleRetryMessage}
|
|
1910
1961
|
{onUpgradePlans}
|
|
1911
1962
|
onClarificationSuggestionSelected={handleClarificationSuggestionSelected}
|
|
@@ -1977,7 +2028,12 @@
|
|
|
1977
2028
|
<span class="rounded bg-[#7BA668]/15 px-1 py-0.5 font-mono text-[11px] font-medium text-[#3C632C]">
|
|
1978
2029
|
<{item.tagName}{item.idAttr ? `#${item.idAttr}` : ''}>
|
|
1979
2030
|
</span>
|
|
1980
|
-
{#if item.
|
|
2031
|
+
{#if item.note?.trim()}
|
|
2032
|
+
<span class="text-gray-400">·</span>
|
|
2033
|
+
<span class="max-w-[220px] truncate text-[11px] text-[#3C632C]" title={item.note}>
|
|
2034
|
+
{item.note.trim()}
|
|
2035
|
+
</span>
|
|
2036
|
+
{:else if item.textSnippet}
|
|
1981
2037
|
<span class="text-gray-400">·</span>
|
|
1982
2038
|
<span class="max-w-[180px] truncate text-[11px] text-gray-600">
|
|
1983
2039
|
{item.textSnippet}
|
|
@@ -2081,6 +2137,7 @@
|
|
|
2081
2137
|
onFilesDropped={(files) => {
|
|
2082
2138
|
void addFilesAsAttachments(files);
|
|
2083
2139
|
}}
|
|
2140
|
+
canSendWithoutText={(selectedElements ?? []).some((element) => !!element.note?.trim())}
|
|
2084
2141
|
/>
|
|
2085
2142
|
</div>
|
|
2086
2143
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import { type TextDirection } from '@widgetic/design-system/components/textDirection';
|
|
3
3
|
import type { ChatConfig, ChatContext } from '../types/index.js';
|
|
4
|
-
import type { ClarificationSuggestion, DesignControlRequest } from '../types/message.js';
|
|
4
|
+
import type { ClarificationSuggestion, DesignControlRequest, VersionRating } from '../types/message.js';
|
|
5
5
|
import type { AttachmentInput, SelectedElementChatReference } from '../types/attachment.js';
|
|
6
6
|
interface ChatMethods {
|
|
7
7
|
sendMessage: (content: string, attachments?: Array<File | AttachmentInput>, options?: {
|
|
@@ -113,6 +113,18 @@ interface Props {
|
|
|
113
113
|
display_order?: number;
|
|
114
114
|
}>, suggestions?: ClarificationSuggestion[], designControls?: DesignControlRequest) => Promise<any>;
|
|
115
115
|
onRestoreCheckpointBackend?: (conversationId: string, checkpointMessageId: string) => Promise<any>;
|
|
116
|
+
/**
|
|
117
|
+
* Keeps the person's thumbs on a version: the assistant message that announced a commit of the widget. Called with the id of the
|
|
118
|
+
* conversation, the id of that message and `up`, `down` or `none` (the rating was taken back); the host sends it to its backend.
|
|
119
|
+
* The two thumbs are drawn next to a version's name only when this is given. Resolve when the rating is kept: a rejection puts the
|
|
120
|
+
* thumb back as it was. The rating is a hint for the host, so a host that cannot keep one should say nothing about it, not fail.
|
|
121
|
+
*/
|
|
122
|
+
onRateVersion?: (conversationId: string, messageId: string, rating: VersionRating) => Promise<unknown>;
|
|
123
|
+
/**
|
|
124
|
+
* The rating each version already has, by the id of the message that announced it, for a host that keeps ratings and gives them
|
|
125
|
+
* back when the chat opens again. What the person presses in this chat is read over it.
|
|
126
|
+
*/
|
|
127
|
+
versionRatings?: Record<string, VersionRating>;
|
|
116
128
|
onTakeScreenshot?: () => Promise<string | null>;
|
|
117
129
|
/** Fires whenever the active conversation ID changes (including initial null → uuid). */
|
|
118
130
|
onConversationChange?: (conversationId: string | null) => void;
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
onAttachmentsChange: (attachments: AttachmentInput[]) => void;
|
|
30
30
|
/** OS file drag-and-drop onto the input area (not attachment reorder). */
|
|
31
31
|
onFilesDropped?: (files: File[]) => void;
|
|
32
|
+
/** A selected part already carries a note, so Send works with an empty box. */
|
|
33
|
+
canSendWithoutText?: boolean;
|
|
32
34
|
/** What the empty box says. Left out, it says the chat's own words (`chat.input.placeholder`). */
|
|
33
35
|
placeholder?: string;
|
|
34
36
|
class?: string;
|
|
@@ -48,6 +50,7 @@
|
|
|
48
50
|
onInputChange,
|
|
49
51
|
onAttachmentsChange,
|
|
50
52
|
onFilesDropped,
|
|
53
|
+
canSendWithoutText = false,
|
|
51
54
|
placeholder,
|
|
52
55
|
class: className = '',
|
|
53
56
|
style = '',
|
|
@@ -107,8 +110,12 @@
|
|
|
107
110
|
// chatLog('ChatInput destroyed for value:', value);
|
|
108
111
|
});
|
|
109
112
|
|
|
113
|
+
function hasSomethingToSend(): boolean {
|
|
114
|
+
return value.trim().length > 0 || attachments.length > 0 || canSendWithoutText;
|
|
115
|
+
}
|
|
116
|
+
|
|
110
117
|
function handleSubmit() {
|
|
111
|
-
if (!
|
|
118
|
+
if (!hasSomethingToSend()) return;
|
|
112
119
|
if (isSending) return;
|
|
113
120
|
|
|
114
121
|
onSend(value.trim(), attachments.length > 0 ? attachments : undefined);
|
|
@@ -339,8 +346,8 @@
|
|
|
339
346
|
class:hover:bg-blue-700={!isGenerating}
|
|
340
347
|
class:bg-red-600={isGenerating}
|
|
341
348
|
class:hover:bg-red-700={isGenerating}
|
|
342
|
-
class:bg-gray-300={!isGenerating && (
|
|
343
|
-
class:cursor-not-allowed={!isGenerating && (
|
|
349
|
+
class:bg-gray-300={!isGenerating && (!hasSomethingToSend() || isSending)}
|
|
350
|
+
class:cursor-not-allowed={!isGenerating && (!hasSomethingToSend() || isSending)}
|
|
344
351
|
onclick={() => {
|
|
345
352
|
if (isGenerating) {
|
|
346
353
|
onStop?.();
|
|
@@ -348,7 +355,7 @@
|
|
|
348
355
|
}
|
|
349
356
|
handleSubmit();
|
|
350
357
|
}}
|
|
351
|
-
disabled={!isGenerating && (
|
|
358
|
+
disabled={!isGenerating && (!hasSomethingToSend() || isSending)}
|
|
352
359
|
aria-label={sendLabel}
|
|
353
360
|
title={sendLabel}
|
|
354
361
|
>
|
|
@@ -17,6 +17,8 @@ interface Props {
|
|
|
17
17
|
onAttachmentsChange: (attachments: AttachmentInput[]) => void;
|
|
18
18
|
/** OS file drag-and-drop onto the input area (not attachment reorder). */
|
|
19
19
|
onFilesDropped?: (files: File[]) => void;
|
|
20
|
+
/** A selected part already carries a note, so Send works with an empty box. */
|
|
21
|
+
canSendWithoutText?: boolean;
|
|
20
22
|
/** What the empty box says. Left out, it says the chat's own words (`chat.input.placeholder`). */
|
|
21
23
|
placeholder?: string;
|
|
22
24
|
class?: string;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { ChatMessage, ChatContext } from '../types/index.js';
|
|
3
|
-
import type { ClarificationSuggestion, DesignControlRequest } from '../types/message.js';
|
|
3
|
+
import type { ClarificationSuggestion, DesignControlRequest, VersionRating } from '../types/message.js';
|
|
4
4
|
import { MESSAGE_COLORS } from '../constants/colors.js';
|
|
5
5
|
import { chatLog } from '../utils/logger.js';
|
|
6
|
+
import { isRatableVersionReply, type VersionThumb } from '../utils/versionRatings.js';
|
|
6
7
|
import { AttachmentDisplay, SuggestionButtons } from './index.js';
|
|
7
8
|
import CodeBlock from './CodeBlock.svelte';
|
|
8
9
|
import { onDestroy, onMount, tick } from 'svelte';
|
|
@@ -66,6 +67,13 @@
|
|
|
66
67
|
generationStream?: string;
|
|
67
68
|
onSuggestionSelected?: (suggestion: string) => void;
|
|
68
69
|
onRestoreCheckpoint?: (messageId: string, messageIndex: number) => void;
|
|
70
|
+
/**
|
|
71
|
+
* Gives each version a thumbs up and a thumbs down next to its name. Called with the id of the assistant message that
|
|
72
|
+
* announced the version and the thumb that was pressed; the host keeps the rating. Without it no thumbs are drawn.
|
|
73
|
+
*/
|
|
74
|
+
onRateVersion?: (messageId: string, pressed: VersionThumb) => void;
|
|
75
|
+
/** The rating each version has, by the id of the message that announced it: what the thumbs show as pressed. */
|
|
76
|
+
versionRatings?: Record<string, VersionRating>;
|
|
69
77
|
onRetryMessage?: (content: string) => void;
|
|
70
78
|
/**
|
|
71
79
|
* What the "Upgrade" button of a failure about the plan or the credits does. Without it the button opens the
|
|
@@ -106,6 +114,8 @@
|
|
|
106
114
|
generationStream = '',
|
|
107
115
|
onSuggestionSelected,
|
|
108
116
|
onRestoreCheckpoint,
|
|
117
|
+
onRateVersion,
|
|
118
|
+
versionRatings = {},
|
|
109
119
|
onRetryMessage,
|
|
110
120
|
onUpgradePlans,
|
|
111
121
|
onClarificationSuggestionSelected,
|
|
@@ -679,6 +689,17 @@
|
|
|
679
689
|
};
|
|
680
690
|
}
|
|
681
691
|
|
|
692
|
+
/**
|
|
693
|
+
* The message a thumbs on this turn's version is given to: the saved assistant reply that announced the commit. Never the stand-in
|
|
694
|
+
* the chat draws for a head that no saved message names, a copy made by Restore, or a reply that was not saved, because the host's
|
|
695
|
+
* backend knows only the messages it saved. Null when the turn has no such reply (a failed prompt, an older prompt with no commit line).
|
|
696
|
+
*/
|
|
697
|
+
function ratableVersionReplyId(turn: ChatTurn): string | null {
|
|
698
|
+
const reply = getTurnCommitReply(turn);
|
|
699
|
+
if (!reply || isRestoreForkContent(reply.messageContent)) return null;
|
|
700
|
+
return isRatableVersionReply(reply) ? reply.id : null;
|
|
701
|
+
}
|
|
702
|
+
|
|
682
703
|
/** Older user turns with no persisted assistant commit — Restore still uses the user message id. */
|
|
683
704
|
function canRestoreLegacyUserTurn(turn: ChatTurn): boolean {
|
|
684
705
|
if (!turn.user) return false;
|
|
@@ -1544,6 +1565,7 @@
|
|
|
1544
1565
|
{/if}
|
|
1545
1566
|
{#if showCommitMetaOnUserTurn(turn)}
|
|
1546
1567
|
{@const commitTitle = getTurnCommitTitle(turn)}
|
|
1568
|
+
{@const versionLabel = getTurnVersionLabel(turn)}
|
|
1547
1569
|
{#if showCommitMeta && commitTitle}
|
|
1548
1570
|
<div class="wc-user-commit-title-row flex w-full min-w-0 mt-1">
|
|
1549
1571
|
<span class="wc-user-commit-title text-xs text-gray-600" title={commitTitle}>
|
|
@@ -1553,11 +1575,44 @@
|
|
|
1553
1575
|
{/if}
|
|
1554
1576
|
<div class="wc-user-commit-meta-ct flex w-full items-center justify-between gap-2 mt-1">
|
|
1555
1577
|
<div class="wc-user-commit-meta-left flex items-center gap-2 min-w-0">
|
|
1556
|
-
|
|
1578
|
+
<!-- Version 1 is the sketch turn. The words read as a second message, so they stay off. Restore stays. -->
|
|
1579
|
+
{#if versionLabel && versionNumberFromLabel(versionLabel) !== 1}
|
|
1557
1580
|
<span class="wc-user-version-label text-xs text-gray-500">
|
|
1558
|
-
{versionLabelText(
|
|
1581
|
+
{versionLabelText(versionLabel, $t)}
|
|
1559
1582
|
</span>
|
|
1560
1583
|
{/if}
|
|
1584
|
+
{#if onRateVersion && !isLoading}
|
|
1585
|
+
{@const ratedMessageId = ratableVersionReplyId(turn)}
|
|
1586
|
+
{#if ratedMessageId}
|
|
1587
|
+
{@const givenRating = versionRatings[ratedMessageId]}
|
|
1588
|
+
<span class="wc-version-rating inline-flex items-center gap-1" role="group" aria-label={$t('chat.messages.rateGroup')}>
|
|
1589
|
+
<button
|
|
1590
|
+
type="button"
|
|
1591
|
+
class="wc-version-rating-btn wc-version-rating-up"
|
|
1592
|
+
aria-pressed={givenRating === 'up'}
|
|
1593
|
+
aria-label={$t('chat.messages.rateUp')}
|
|
1594
|
+
title={$t('chat.messages.rateUp')}
|
|
1595
|
+
onclick={() => onRateVersion?.(ratedMessageId, 'up')}
|
|
1596
|
+
>
|
|
1597
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill={givenRating === 'up' ? 'currentColor' : 'none'} stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
1598
|
+
<path d="M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3" />
|
|
1599
|
+
</svg>
|
|
1600
|
+
</button>
|
|
1601
|
+
<button
|
|
1602
|
+
type="button"
|
|
1603
|
+
class="wc-version-rating-btn wc-version-rating-down"
|
|
1604
|
+
aria-pressed={givenRating === 'down'}
|
|
1605
|
+
aria-label={$t('chat.messages.rateDown')}
|
|
1606
|
+
title={$t('chat.messages.rateDown')}
|
|
1607
|
+
onclick={() => onRateVersion?.(ratedMessageId, 'down')}
|
|
1608
|
+
>
|
|
1609
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill={givenRating === 'down' ? 'currentColor' : 'none'} stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
1610
|
+
<path d="M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17" />
|
|
1611
|
+
</svg>
|
|
1612
|
+
</button>
|
|
1613
|
+
</span>
|
|
1614
|
+
{/if}
|
|
1615
|
+
{/if}
|
|
1561
1616
|
{#if showCommitMeta && getTurnCommitShort(turn)}
|
|
1562
1617
|
<span class="wc-user-commit-sha whitespace-nowrap font-mono text-xs text-gray-500">
|
|
1563
1618
|
{$t('chat.messages.commitId', { id: getTurnCommitShort(turn) ?? '' })}
|
|
@@ -1565,7 +1620,7 @@
|
|
|
1565
1620
|
{/if}
|
|
1566
1621
|
</div>
|
|
1567
1622
|
{#if !turn.user?.id?.startsWith('version-fork-') && !isLoading && ((commitReply && (canRestoreToMessage(commitReply) || isHeadCommitReply(commitReply))) || canRestoreFailedLastTurn(turn))}
|
|
1568
|
-
{@const restoreIsCurrentHead = !!(commitReply && isHeadCommitReply(commitReply) && versionNumberFromLabel(
|
|
1623
|
+
{@const restoreIsCurrentHead = !!(commitReply && isHeadCommitReply(commitReply) && versionNumberFromLabel(versionLabel) !== 1)}
|
|
1569
1624
|
<button
|
|
1570
1625
|
class="restore-checkpoint-btn shrink-0"
|
|
1571
1626
|
disabled={restoreIsCurrentHead}
|
|
@@ -1865,6 +1920,44 @@
|
|
|
1865
1920
|
cursor: not-allowed;
|
|
1866
1921
|
pointer-events: none;
|
|
1867
1922
|
}
|
|
1923
|
+
|
|
1924
|
+
/* The thumbs next to a version's name. A pressed thumb is filled and takes the colour of what it says. */
|
|
1925
|
+
.wc-version-rating-btn {
|
|
1926
|
+
display: inline-flex;
|
|
1927
|
+
align-items: center;
|
|
1928
|
+
justify-content: center;
|
|
1929
|
+
width: 22px;
|
|
1930
|
+
height: 22px;
|
|
1931
|
+
padding: 0;
|
|
1932
|
+
background: transparent;
|
|
1933
|
+
color: #9ca3af;
|
|
1934
|
+
border: 1px solid transparent;
|
|
1935
|
+
border-radius: 6px;
|
|
1936
|
+
cursor: pointer;
|
|
1937
|
+
transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
.wc-version-rating-btn:hover {
|
|
1941
|
+
background: rgba(0, 0, 0, 0.06);
|
|
1942
|
+
color: #555;
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
.wc-version-rating-btn:focus-visible {
|
|
1946
|
+
outline: 2px solid #93c5fd;
|
|
1947
|
+
outline-offset: 1px;
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
.wc-version-rating-btn[aria-pressed='true'].wc-version-rating-up {
|
|
1951
|
+
color: #15803d;
|
|
1952
|
+
background: #f0fdf4;
|
|
1953
|
+
border-color: #bbf7d0;
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
.wc-version-rating-btn[aria-pressed='true'].wc-version-rating-down {
|
|
1957
|
+
color: #b91c1c;
|
|
1958
|
+
background: #fef2f2;
|
|
1959
|
+
border-color: #fecaca;
|
|
1960
|
+
}
|
|
1868
1961
|
|
|
1869
1962
|
.retry-codegen-btn {
|
|
1870
1963
|
color: #b91c1c;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ChatMessage, ChatContext } from '../types/index.js';
|
|
2
|
-
import type { ClarificationSuggestion, DesignControlRequest } from '../types/message.js';
|
|
2
|
+
import type { ClarificationSuggestion, DesignControlRequest, VersionRating } from '../types/message.js';
|
|
3
|
+
import { type VersionThumb } from '../utils/versionRatings.js';
|
|
3
4
|
import type { Snippet } from 'svelte';
|
|
4
5
|
interface Props {
|
|
5
6
|
class?: string;
|
|
@@ -53,6 +54,13 @@ interface Props {
|
|
|
53
54
|
generationStream?: string;
|
|
54
55
|
onSuggestionSelected?: (suggestion: string) => void;
|
|
55
56
|
onRestoreCheckpoint?: (messageId: string, messageIndex: number) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Gives each version a thumbs up and a thumbs down next to its name. Called with the id of the assistant message that
|
|
59
|
+
* announced the version and the thumb that was pressed; the host keeps the rating. Without it no thumbs are drawn.
|
|
60
|
+
*/
|
|
61
|
+
onRateVersion?: (messageId: string, pressed: VersionThumb) => void;
|
|
62
|
+
/** The rating each version has, by the id of the message that announced it: what the thumbs show as pressed. */
|
|
63
|
+
versionRatings?: Record<string, VersionRating>;
|
|
56
64
|
onRetryMessage?: (content: string) => void;
|
|
57
65
|
/**
|
|
58
66
|
* What the "Upgrade" button of a failure about the plan or the credits does. Without it the button opens the
|
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: (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">;
|
|
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: () => 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">;
|
|
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: 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">;
|
|
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/dist/i18n/messages.d.ts
CHANGED
|
@@ -58,6 +58,10 @@ export declare const CHAT_MESSAGES: {
|
|
|
58
58
|
readonly 'chat.messages.restore': "Restore Checkpoint";
|
|
59
59
|
readonly 'chat.messages.restoreTitle': "Restore widget code to this prompt's commit";
|
|
60
60
|
readonly 'chat.messages.alreadyHead': "This checkpoint is already HEAD";
|
|
61
|
+
/** The two thumbs next to a version's name, when the page gave the chat a way to keep a rating (`onRateVersion`). */
|
|
62
|
+
readonly 'chat.messages.rateGroup': "Rate this version";
|
|
63
|
+
readonly 'chat.messages.rateUp': "This version is good";
|
|
64
|
+
readonly 'chat.messages.rateDown': "This version is not good";
|
|
61
65
|
/**
|
|
62
66
|
* Versions are named "Version 4" between the page and the chat, and in the lines the chat saves ("Restored from Version
|
|
63
67
|
* 4"): the chat reads the number out of those words. It says them again in the page's language with these three.
|
package/dist/i18n/messages.js
CHANGED
|
@@ -62,6 +62,10 @@ export const CHAT_MESSAGES = {
|
|
|
62
62
|
'chat.messages.restore': 'Restore Checkpoint',
|
|
63
63
|
'chat.messages.restoreTitle': 'Restore widget code to this prompt\'s commit',
|
|
64
64
|
'chat.messages.alreadyHead': 'This checkpoint is already HEAD',
|
|
65
|
+
/** The two thumbs next to a version's name, when the page gave the chat a way to keep a rating (`onRateVersion`). */
|
|
66
|
+
'chat.messages.rateGroup': 'Rate this version',
|
|
67
|
+
'chat.messages.rateUp': 'This version is good',
|
|
68
|
+
'chat.messages.rateDown': 'This version is not good',
|
|
65
69
|
/**
|
|
66
70
|
* Versions are named "Version 4" between the page and the chat, and in the lines the chat saves ("Restored from Version
|
|
67
71
|
* 4"): the chat reads the number out of those words. It says them again in the page's language with these three.
|
package/dist/types/message.d.ts
CHANGED
|
@@ -86,6 +86,12 @@ export interface DesignControlRequest {
|
|
|
86
86
|
*/
|
|
87
87
|
compositionId?: string | null;
|
|
88
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* What a person says about a version of a widget with the thumbs next to the version's name: `up`, `down`, or `none`
|
|
91
|
+
* to take the rating back. The chat tells the host with `onRateVersion`; the three words are the ones the gateway's
|
|
92
|
+
* rating call takes, so a host can pass them on as they are.
|
|
93
|
+
*/
|
|
94
|
+
export type VersionRating = 'up' | 'down' | 'none';
|
|
89
95
|
/** One suggestion chip on a clarification card — display copy plus the
|
|
90
96
|
* machine-readable behavior of tapping it. The client keys off `intent`;
|
|
91
97
|
* `label` is never parsed. */
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { fileTypeConfig, detectFileType, validateFile, validateFiles, formatFileSize, getFileExtension, generateFileId, createFilePreview, createPendingAttachment, getAcceptString, supportsPreview, getFileIcon, compressImage } from './fileUtils.js';
|
|
2
|
+
export { VERSION_RATINGS, ratingAfterPress, ratingOfVersion, isRatableVersionReply } from './versionRatings.js';
|
|
3
|
+
export type { VersionThumb } from './versionRatings.js';
|
|
2
4
|
export { setLogsEnabled, chatLog, chatWarn, chatError } from './logger.js';
|
|
3
5
|
export type { AttachmentType, AttachmentValidation, PendingAttachment, UploadStatus } from '../types/index.js';
|
package/dist/utils/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// File utilities
|
|
2
2
|
export { fileTypeConfig, detectFileType, validateFile, validateFiles, formatFileSize, getFileExtension, generateFileId, createFilePreview, createPendingAttachment, getAcceptString, supportsPreview, getFileIcon, compressImage } from './fileUtils.js';
|
|
3
|
+
// The thumbs next to a version
|
|
4
|
+
export { VERSION_RATINGS, ratingAfterPress, ratingOfVersion, isRatableVersionReply } from './versionRatings.js';
|
|
3
5
|
// Logger
|
|
4
6
|
export { setLogsEnabled, chatLog, chatWarn, chatError } from './logger.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file versionRatings.ts
|
|
3
|
+
* @description The rules of the thumbs next to a version in the chat, kept out of the components so they can be tested on their own:
|
|
4
|
+
* what a press of a thumb makes of the rating a version has, and which reply can be rated at all.
|
|
5
|
+
*
|
|
6
|
+
* A version is the assistant message that announced a commit of the widget. That message is what a rating is given to, and its id is what
|
|
7
|
+
* the host passes on, so only a message that was saved can carry one.
|
|
8
|
+
*/
|
|
9
|
+
import type { ChatMessage, VersionRating } from '../types/index.js';
|
|
10
|
+
/** What a person can press. */
|
|
11
|
+
export type VersionThumb = 'up' | 'down';
|
|
12
|
+
/** The three words a host is told, in the order they are listed in the documentation. */
|
|
13
|
+
export declare const VERSION_RATINGS: readonly VersionRating[];
|
|
14
|
+
/**
|
|
15
|
+
* What a press of a thumb makes of the rating a version has. The thumb that is already chosen takes the rating back when it is
|
|
16
|
+
* pressed again (`none`); the other thumb replaces it.
|
|
17
|
+
*/
|
|
18
|
+
export declare function ratingAfterPress(current: VersionRating, pressed: VersionThumb): VersionRating;
|
|
19
|
+
/**
|
|
20
|
+
* Whether the reply that announces a version can be rated: it has an id the host's backend knows (it was saved, it is not a stand-in the
|
|
21
|
+
* chat made up and not a copy Restore made), it did not fail, and it was not undone by a restore.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isRatableVersionReply(reply: Pick<ChatMessage, 'id' | '_optimistic' | '_failed' | 'rolledBackAt'> | null | undefined): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The rating a version has: the person's latest press in this chat, else what the host seeded (a host that keeps ratings gives them
|
|
26
|
+
* back when the chat opens again), else none. A word that is not one of the three is no word.
|
|
27
|
+
*/
|
|
28
|
+
export declare function ratingOfVersion(messageId: string, chosen: Readonly<Record<string, VersionRating>>, seeded: Readonly<Record<string, VersionRating>>): VersionRating;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** The three words a host is told, in the order they are listed in the documentation. */
|
|
2
|
+
export const VERSION_RATINGS = ['up', 'down', 'none'];
|
|
3
|
+
/**
|
|
4
|
+
* What a press of a thumb makes of the rating a version has. The thumb that is already chosen takes the rating back when it is
|
|
5
|
+
* pressed again (`none`); the other thumb replaces it.
|
|
6
|
+
*/
|
|
7
|
+
export function ratingAfterPress(current, pressed) {
|
|
8
|
+
return current === pressed ? 'none' : pressed;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The ids the chat makes up for messages that are not a version saved by a generation: the copy Restore appends (`version-fork-…`)
|
|
12
|
+
* and the stand-in the chat draws while the widget's head is ahead of every saved message (`fallback-head-…`).
|
|
13
|
+
*/
|
|
14
|
+
const ID_PREFIXES_OF_STAND_INS = ['version-fork-', 'fallback-head-'];
|
|
15
|
+
/**
|
|
16
|
+
* Whether the reply that announces a version can be rated: it has an id the host's backend knows (it was saved, it is not a stand-in the
|
|
17
|
+
* chat made up and not a copy Restore made), it did not fail, and it was not undone by a restore.
|
|
18
|
+
*/
|
|
19
|
+
export function isRatableVersionReply(reply) {
|
|
20
|
+
if (!reply || typeof reply.id !== 'string' || reply.id === '')
|
|
21
|
+
return false;
|
|
22
|
+
if (reply._optimistic === true || reply._failed === true)
|
|
23
|
+
return false;
|
|
24
|
+
if (reply.rolledBackAt)
|
|
25
|
+
return false;
|
|
26
|
+
return !ID_PREFIXES_OF_STAND_INS.some((prefix) => reply.id.startsWith(prefix));
|
|
27
|
+
}
|
|
28
|
+
/** A word of a record that is its own: an id never reads a name every object has (`constructor`, `toString`). */
|
|
29
|
+
function ownRating(ratings, messageId) {
|
|
30
|
+
if (!Object.prototype.hasOwnProperty.call(ratings, messageId))
|
|
31
|
+
return undefined;
|
|
32
|
+
const rating = ratings[messageId];
|
|
33
|
+
return VERSION_RATINGS.includes(rating) ? rating : undefined;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The rating a version has: the person's latest press in this chat, else what the host seeded (a host that keeps ratings gives them
|
|
37
|
+
* back when the chat opens again), else none. A word that is not one of the three is no word.
|
|
38
|
+
*/
|
|
39
|
+
export function ratingOfVersion(messageId, chosen, seeded) {
|
|
40
|
+
return ownRating(chosen, messageId) ?? ownRating(seeded, messageId) ?? 'none';
|
|
41
|
+
}
|