@widgetic/chat 0.1.17 → 0.1.19
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 +104 -0
- package/dist/components/ActionBar.svelte +19 -15
- package/dist/components/AttachmentDisplay.svelte +54 -26
- package/dist/components/Chat.svelte +106 -58
- package/dist/components/Chat.svelte.d.ts +29 -0
- package/dist/components/ChatHeader.svelte +21 -21
- package/dist/components/ChatInput.svelte +39 -18
- package/dist/components/ChatInput.svelte.d.ts +1 -0
- package/dist/components/ChatMessages.svelte +93 -36
- package/dist/components/ChatMessages.svelte.d.ts +8 -0
- package/dist/components/CodeBlock.svelte +14 -9
- package/dist/components/ContextPreview.svelte +8 -3
- package/dist/components/StatusIndicator.svelte +10 -5
- package/dist/components/SuggestionButtons.svelte +19 -64
- package/dist/i18n/index.d.ts +4 -0
- package/dist/i18n/index.js +4 -0
- package/dist/i18n/labels.d.ts +31 -0
- package/dist/i18n/labels.js +69 -0
- package/dist/i18n/language.d.ts +22 -0
- package/dist/i18n/language.js +31 -0
- package/dist/i18n/messages.d.ts +173 -0
- package/dist/i18n/messages.js +182 -0
- package/dist/i18n/suggestions.d.ts +5 -0
- package/dist/i18n/suggestions.js +66 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/package.json +3 -1
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { ChatContext } from '../types/index.js';
|
|
3
|
+
import { useChatLanguage } from '../i18n/language.js';
|
|
4
|
+
import { contextTypeLabel } from '../i18n/labels.js';
|
|
5
|
+
|
|
6
|
+
// The words of the card, in the language of the chat above
|
|
7
|
+
const { t } = useChatLanguage();
|
|
3
8
|
|
|
4
9
|
interface Props {
|
|
5
10
|
context: ChatContext;
|
|
@@ -16,9 +21,9 @@
|
|
|
16
21
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
17
22
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
18
23
|
<button
|
|
19
|
-
class="flex items-center justify-between p-3 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-600 rounded-lg cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors shadow-sm hover:shadow-md w-full text-
|
|
24
|
+
class="flex items-center justify-between p-3 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-600 rounded-lg cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors shadow-sm hover:shadow-md w-full text-start"
|
|
20
25
|
onclick={handleClick}
|
|
21
|
-
aria-label=
|
|
26
|
+
aria-label={$t('chat.contextPreview.expand', { name: context.title || context.id })}
|
|
22
27
|
>
|
|
23
28
|
<div class="flex items-center gap-3">
|
|
24
29
|
{#if context.thumbnail}
|
|
@@ -48,7 +53,7 @@
|
|
|
48
53
|
{context.title || context.id}
|
|
49
54
|
</h4>
|
|
50
55
|
<p class="text-xs text-gray-500 dark:text-gray-400 capitalize">
|
|
51
|
-
{context.type}
|
|
56
|
+
{$t('chat.header.typeChat', { type: contextTypeLabel(context.type, $t) })}
|
|
52
57
|
</p>
|
|
53
58
|
</div>
|
|
54
59
|
</div>
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { useChatLanguage } from '../i18n/language.js';
|
|
3
|
+
|
|
4
|
+
// The words of the indicator, in the language of the chat above
|
|
5
|
+
const { t } = useChatLanguage();
|
|
6
|
+
|
|
2
7
|
interface Props {
|
|
3
8
|
status: 'active' | 'completed' | 'loading' | 'error';
|
|
4
9
|
messageCount?: number;
|
|
@@ -13,7 +18,7 @@
|
|
|
13
18
|
case 'completed':
|
|
14
19
|
return {
|
|
15
20
|
icon: '✅',
|
|
16
|
-
text: '
|
|
21
|
+
text: $t('chat.status.completed'),
|
|
17
22
|
color: 'text-green-600',
|
|
18
23
|
bgColor: 'bg-green-100',
|
|
19
24
|
borderColor: 'border-green-200'
|
|
@@ -21,7 +26,7 @@
|
|
|
21
26
|
case 'loading':
|
|
22
27
|
return {
|
|
23
28
|
icon: '⏳',
|
|
24
|
-
text: '
|
|
29
|
+
text: $t('chat.status.processing'),
|
|
25
30
|
color: 'text-blue-600',
|
|
26
31
|
bgColor: 'bg-blue-100',
|
|
27
32
|
borderColor: 'border-blue-200'
|
|
@@ -29,7 +34,7 @@
|
|
|
29
34
|
case 'error':
|
|
30
35
|
return {
|
|
31
36
|
icon: '❌',
|
|
32
|
-
text: '
|
|
37
|
+
text: $t('chat.status.error'),
|
|
33
38
|
color: 'text-red-600',
|
|
34
39
|
bgColor: 'bg-red-100',
|
|
35
40
|
borderColor: 'border-red-200'
|
|
@@ -37,7 +42,7 @@
|
|
|
37
42
|
default: // active
|
|
38
43
|
return {
|
|
39
44
|
icon: '💬',
|
|
40
|
-
text: '
|
|
45
|
+
text: $t('chat.status.active'),
|
|
41
46
|
color: 'text-gray-600',
|
|
42
47
|
bgColor: 'bg-gray-100',
|
|
43
48
|
borderColor: 'border-gray-200'
|
|
@@ -72,7 +77,7 @@
|
|
|
72
77
|
{config.text}
|
|
73
78
|
{#if messageCount > 0 && status !== 'loading'}
|
|
74
79
|
<span class="message-count opacity-75">
|
|
75
|
-
(
|
|
80
|
+
{$t('chat.status.messageCount', { count: messageCount })}
|
|
76
81
|
</span>
|
|
77
82
|
{/if}
|
|
78
83
|
</span>
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
import { createEventDispatcher } from 'svelte';
|
|
3
3
|
import { chatLog } from '../utils/logger.js';
|
|
4
4
|
import type { ChatContext } from '../types/context.js';
|
|
5
|
+
import { useChatLanguage } from '../i18n/language.js';
|
|
6
|
+
import { suggestionKeysFor, suggestionTitleKeyFor } from '../i18n/suggestions.js';
|
|
7
|
+
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
8
|
+
|
|
9
|
+
// The words of the ideas, in the language of the chat above
|
|
10
|
+
const { t } = useChatLanguage();
|
|
11
|
+
|
|
12
|
+
// The way the screen is read: a suggestion is a sentence the assistant wrote, and reads by its own first letter on a right to left screen.
|
|
13
|
+
const textDirection = useTextDirection();
|
|
5
14
|
|
|
6
15
|
// Props
|
|
7
16
|
interface Props {
|
|
@@ -14,95 +23,41 @@
|
|
|
14
23
|
|
|
15
24
|
const dispatch = createEventDispatcher();
|
|
16
25
|
|
|
17
|
-
// Get context-specific suggestions
|
|
18
|
-
function getContextSuggestions(): string[] {
|
|
19
|
-
switch (context.type) {
|
|
20
|
-
case 'frame':
|
|
21
|
-
return [
|
|
22
|
-
'Generate code from this design',
|
|
23
|
-
'Suggest improvements for this layout',
|
|
24
|
-
'Add interactive functionality',
|
|
25
|
-
'Make this responsive for mobile',
|
|
26
|
-
'Add animations and transitions'
|
|
27
|
-
];
|
|
28
|
-
case 'text':
|
|
29
|
-
return [
|
|
30
|
-
'Help improve this writing',
|
|
31
|
-
'Check grammar and style',
|
|
32
|
-
'Suggest alternative phrasing',
|
|
33
|
-
'Summarize this content',
|
|
34
|
-
'Expand on this topic'
|
|
35
|
-
];
|
|
36
|
-
case 'image':
|
|
37
|
-
return [
|
|
38
|
-
'Describe what you see in this image',
|
|
39
|
-
'Generate alt text for accessibility',
|
|
40
|
-
'Suggest design improvements',
|
|
41
|
-
'Convert image to code',
|
|
42
|
-
'Extract text from this image'
|
|
43
|
-
];
|
|
44
|
-
case 'document':
|
|
45
|
-
return [
|
|
46
|
-
'Summarize this document',
|
|
47
|
-
'Extract key points',
|
|
48
|
-
'Check for errors or inconsistencies',
|
|
49
|
-
'Suggest improvements',
|
|
50
|
-
'Create an outline'
|
|
51
|
-
];
|
|
52
|
-
default:
|
|
53
|
-
return [
|
|
54
|
-
'Ask a question about this content',
|
|
55
|
-
'Get suggestions for improvement',
|
|
56
|
-
'Explain what you see here',
|
|
57
|
-
'Help me understand this better',
|
|
58
|
-
'What can I do with this?'
|
|
59
|
-
];
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
26
|
function handleSuggestionClick(suggestion: string) {
|
|
64
27
|
// chatLog('Suggestion clicked:', suggestion);
|
|
65
28
|
dispatch('suggestionSelected', { suggestion });
|
|
66
29
|
}
|
|
67
30
|
|
|
68
31
|
// Get suggestions for current context
|
|
69
|
-
let
|
|
32
|
+
let suggestionKeys = $derived(suggestionKeysFor(context.type));
|
|
33
|
+
let titleKey = $derived(suggestionTitleKeyFor(context.type));
|
|
70
34
|
</script>
|
|
71
35
|
|
|
72
|
-
{#if visible &&
|
|
36
|
+
{#if visible && suggestionKeys.length > 0}
|
|
73
37
|
<div class="suggestion-container">
|
|
74
38
|
<div class="suggestion-header">
|
|
75
39
|
<h4 class="suggestion-title">
|
|
76
|
-
{
|
|
77
|
-
Suggested actions for this widget
|
|
78
|
-
{:else if context.type === 'text'}
|
|
79
|
-
Suggested text improvements
|
|
80
|
-
{:else if context.type === 'image'}
|
|
81
|
-
Suggested image analysis
|
|
82
|
-
{:else if context.type === 'document'}
|
|
83
|
-
Suggested document actions
|
|
84
|
-
{:else}
|
|
85
|
-
Suggested questions
|
|
86
|
-
{/if}
|
|
40
|
+
{$t(titleKey)}
|
|
87
41
|
</h4>
|
|
88
42
|
{#if onHide}
|
|
89
43
|
<button
|
|
90
44
|
class="hide-suggestions-btn"
|
|
91
45
|
onclick={onHide}
|
|
92
46
|
>
|
|
93
|
-
|
|
47
|
+
{$t('chat.suggestions.hide')}
|
|
94
48
|
</button>
|
|
95
49
|
{/if}
|
|
96
50
|
</div>
|
|
97
51
|
|
|
98
52
|
<div class="suggestion-grid">
|
|
99
|
-
{#each
|
|
53
|
+
{#each suggestionKeys as suggestionKey (suggestionKey)}
|
|
54
|
+
{@const suggestion = $t(suggestionKey)}
|
|
100
55
|
<button
|
|
101
56
|
class="suggestion-button"
|
|
102
57
|
onclick={() => handleSuggestionClick(suggestion)}
|
|
103
58
|
title={suggestion}
|
|
104
59
|
>
|
|
105
|
-
<span class="suggestion-text">{suggestion}</span>
|
|
60
|
+
<span class="suggestion-text" dir={dirForUserText($textDirection)}>{suggestion}</span>
|
|
106
61
|
<svg class="suggestion-arrow" viewBox="0 0 20 20" fill="currentColor">
|
|
107
62
|
<path fill-rule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clip-rule="evenodd" />
|
|
108
63
|
</svg>
|
|
@@ -175,7 +130,7 @@
|
|
|
175
130
|
border-radius: 0.5rem;
|
|
176
131
|
color: #374151;
|
|
177
132
|
font-size: 0.875rem;
|
|
178
|
-
text-align:
|
|
133
|
+
text-align: start;
|
|
179
134
|
cursor: pointer;
|
|
180
135
|
transition: all 0.2s ease;
|
|
181
136
|
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
|
@@ -201,7 +156,7 @@
|
|
|
201
156
|
.suggestion-arrow {
|
|
202
157
|
width: 1rem;
|
|
203
158
|
height: 1rem;
|
|
204
|
-
margin-
|
|
159
|
+
margin-inline-start: 0.75rem;
|
|
205
160
|
opacity: 0.5;
|
|
206
161
|
transition: all 0.2s ease;
|
|
207
162
|
flex-shrink: 0;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { CHAT_MESSAGES, type ChatMessageKey } from './messages.js';
|
|
2
|
+
export { checkChatMessages, provideChatLanguage, useChatLanguage } from './language.js';
|
|
3
|
+
export { actionFailureKey, contextTypeLabel, fileSizeText, versionLabelText } from './labels.js';
|
|
4
|
+
export { suggestionKeysFor, suggestionTitleKeyFor } from './suggestions.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { CHAT_MESSAGES } from './messages.js';
|
|
2
|
+
export { checkChatMessages, provideChatLanguage, useChatLanguage } from './language.js';
|
|
3
|
+
export { actionFailureKey, contextTypeLabel, fileSizeText, versionLabelText } from './labels.js';
|
|
4
|
+
export { suggestionKeysFor, suggestionTitleKeyFor } from './suggestions.js';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Translate } from '@widgetic/design-system/i18n';
|
|
2
|
+
import type { ChatMessageKey } from './messages.js';
|
|
3
|
+
/**
|
|
4
|
+
* A chat is attached to one kind of thing (a frame, a text, an image ...), and the host names it by an English word that
|
|
5
|
+
* does not change with the language. This turns that word into what a person reads in their language, and shows a kind it
|
|
6
|
+
* does not know as it is.
|
|
7
|
+
*/
|
|
8
|
+
type Translator = Translate<ChatMessageKey>;
|
|
9
|
+
/** The kind of thing a chat is about, by the name the host keeps it under ("frame"). */
|
|
10
|
+
export declare function contextTypeLabel(type: string, t: Translator): string;
|
|
11
|
+
/**
|
|
12
|
+
* How a version label reads on screen.
|
|
13
|
+
*
|
|
14
|
+
* Between the page and the chat, and in the line the chat saves when a version is restored, versions are named "Version
|
|
15
|
+
* 4", "Restored from Version 4" and "Restored from a previous version": the chat finds the number of a version in those
|
|
16
|
+
* words (to put "You are here" on the right turn), so they are kept as they are and said again here in the page's
|
|
17
|
+
* language. A label of any other shape (one the page made up) is shown as it was given.
|
|
18
|
+
*/
|
|
19
|
+
export declare function versionLabelText(label: string | null, t: Translator): string | null;
|
|
20
|
+
/**
|
|
21
|
+
* The size of a file as the biggest unit that keeps it above 1 ("1.5 MB"): the unit comes from the page's words, and the
|
|
22
|
+
* number is written the way `locale` writes numbers, with up to two decimals and no thousands separator. A file bigger
|
|
23
|
+
* than a gigabyte stays in gigabytes. A file with no size (or a size of 0, or one that is not a number) has no text.
|
|
24
|
+
*/
|
|
25
|
+
export declare function fileSizeText(bytes: number | null | undefined, t: Translator, locale: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* The sentence for an action of the action bar that failed. The bar reports a "screenshot" or a "recording"; any other
|
|
28
|
+
* kind (one a newer bar might report) gets the general sentence.
|
|
29
|
+
*/
|
|
30
|
+
export declare function actionFailureKey(type: string): ChatMessageKey;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const CONTEXT_TYPE_KEYS = {
|
|
2
|
+
frame: 'chat.contextType.frame',
|
|
3
|
+
text: 'chat.contextType.text',
|
|
4
|
+
image: 'chat.contextType.image',
|
|
5
|
+
document: 'chat.contextType.document',
|
|
6
|
+
canvas: 'chat.contextType.canvas'
|
|
7
|
+
};
|
|
8
|
+
/** The kind of thing a chat is about, by the name the host keeps it under ("frame"). */
|
|
9
|
+
export function contextTypeLabel(type, t) {
|
|
10
|
+
// Only the table's own entries: a kind called "constructor" is not a method of the table.
|
|
11
|
+
const key = Object.prototype.hasOwnProperty.call(CONTEXT_TYPE_KEYS, type) ? CONTEXT_TYPE_KEYS[type] : undefined;
|
|
12
|
+
return key ? t(key) : type;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* How a version label reads on screen.
|
|
16
|
+
*
|
|
17
|
+
* Between the page and the chat, and in the line the chat saves when a version is restored, versions are named "Version
|
|
18
|
+
* 4", "Restored from Version 4" and "Restored from a previous version": the chat finds the number of a version in those
|
|
19
|
+
* words (to put "You are here" on the right turn), so they are kept as they are and said again here in the page's
|
|
20
|
+
* language. A label of any other shape (one the page made up) is shown as it was given.
|
|
21
|
+
*/
|
|
22
|
+
export function versionLabelText(label, t) {
|
|
23
|
+
if (!label)
|
|
24
|
+
return label;
|
|
25
|
+
const sayVersion = (name) => {
|
|
26
|
+
const version = /^Version\s+(\d+)$/i.exec(name.trim());
|
|
27
|
+
// The number is given as text, so it is written with the digits it came with in every language
|
|
28
|
+
if (version)
|
|
29
|
+
return t('chat.messages.version', { number: version[1] });
|
|
30
|
+
if (/^a previous version$/i.test(name.trim()))
|
|
31
|
+
return t('chat.messages.previousVersion');
|
|
32
|
+
return name;
|
|
33
|
+
};
|
|
34
|
+
const restored = /^Restored from (.+)$/i.exec(label.trim());
|
|
35
|
+
if (restored)
|
|
36
|
+
return t('chat.messages.restoredFrom', { label: sayVersion(restored[1]) });
|
|
37
|
+
return sayVersion(label);
|
|
38
|
+
}
|
|
39
|
+
/** The message of each unit of size of a file, from bytes to gigabytes. */
|
|
40
|
+
const SIZE_KEYS = ['chat.size.bytes', 'chat.size.kb', 'chat.size.mb', 'chat.size.gb'];
|
|
41
|
+
/**
|
|
42
|
+
* The size of a file as the biggest unit that keeps it above 1 ("1.5 MB"): the unit comes from the page's words, and the
|
|
43
|
+
* number is written the way `locale` writes numbers, with up to two decimals and no thousands separator. A file bigger
|
|
44
|
+
* than a gigabyte stays in gigabytes. A file with no size (or a size of 0, or one that is not a number) has no text.
|
|
45
|
+
*/
|
|
46
|
+
export function fileSizeText(bytes, t, locale) {
|
|
47
|
+
if (typeof bytes !== 'number' || !Number.isFinite(bytes) || !(bytes > 0))
|
|
48
|
+
return '';
|
|
49
|
+
// Divided step by step, so a size of exactly 1024 × 1024 is "1 MB", never "1024 KB" (a logarithm can be a hair short)
|
|
50
|
+
let size = bytes;
|
|
51
|
+
let unitIndex = 0;
|
|
52
|
+
while (size >= 1024 && unitIndex < SIZE_KEYS.length - 1) {
|
|
53
|
+
size /= 1024;
|
|
54
|
+
unitIndex += 1;
|
|
55
|
+
}
|
|
56
|
+
const written = new Intl.NumberFormat(locale, { maximumFractionDigits: 2, useGrouping: false }).format(size);
|
|
57
|
+
return t(SIZE_KEYS[unitIndex], { size: written });
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The sentence for an action of the action bar that failed. The bar reports a "screenshot" or a "recording"; any other
|
|
61
|
+
* kind (one a newer bar might report) gets the general sentence.
|
|
62
|
+
*/
|
|
63
|
+
export function actionFailureKey(type) {
|
|
64
|
+
if (type === 'screenshot')
|
|
65
|
+
return 'chat.error.screenshotActionFailed';
|
|
66
|
+
if (type === 'recording')
|
|
67
|
+
return 'chat.error.recordingActionFailed';
|
|
68
|
+
return 'chat.error.actionFailed';
|
|
69
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type MessageOverrides, type MessageProblem } from '@widgetic/design-system/i18n';
|
|
2
|
+
/**
|
|
3
|
+
* Called by the root component of a chat while it is created, so everything inside it speaks the page's language.
|
|
4
|
+
* It gives back the words as stores and `update(settings)` for when the page sets the language again.
|
|
5
|
+
*/
|
|
6
|
+
export declare const provideChatLanguage: any;
|
|
7
|
+
/**
|
|
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
|
+
* changes when the page sets the language again. Outside a chat (a part used on its own) it speaks English.
|
|
10
|
+
*/
|
|
11
|
+
export declare const useChatLanguage: any;
|
|
12
|
+
/**
|
|
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
|
+
* page's language, from `useChatLanguage`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const translateEnglish: any;
|
|
17
|
+
/**
|
|
18
|
+
* Checks a page's `messages` against the chat's catalog without showing anything: a key that does not exist (with the
|
|
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
|
|
20
|
+
* is never given. An empty list means every message will be used. For a test or a build step of the page.
|
|
21
|
+
*/
|
|
22
|
+
export declare function checkChatMessages(messages: MessageOverrides): MessageProblem[];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createI18n, findMessageProblems } from '@widgetic/design-system/i18n';
|
|
2
|
+
import { CHAT_MESSAGES } from './messages.js';
|
|
3
|
+
/**
|
|
4
|
+
* The language of a chat on a page. `Chat` is the root: it takes `locale` and `messages`, makes the language here, and
|
|
5
|
+
* every part of the chat below it reads its words from it (`useChatLanguage`). The context belongs to one root, so two
|
|
6
|
+
* chats on a page can speak two languages.
|
|
7
|
+
*/
|
|
8
|
+
const chatWords = createI18n({ catalog: CHAT_MESSAGES, label: 'Chat' });
|
|
9
|
+
/**
|
|
10
|
+
* Called by the root component of a chat while it is created, so everything inside it speaks the page's language.
|
|
11
|
+
* It gives back the words as stores and `update(settings)` for when the page sets the language again.
|
|
12
|
+
*/
|
|
13
|
+
export const provideChatLanguage = chatWords.provideI18n;
|
|
14
|
+
/**
|
|
15
|
+
* 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
|
|
16
|
+
* changes when the page sets the language again. Outside a chat (a part used on its own) it speaks English.
|
|
17
|
+
*/
|
|
18
|
+
export const useChatLanguage = chatWords.useI18n;
|
|
19
|
+
/**
|
|
20
|
+
* The English `t` of the chat, for code that has no component around it. The screens of the chat get their words, in the
|
|
21
|
+
* page's language, from `useChatLanguage`.
|
|
22
|
+
*/
|
|
23
|
+
export const translateEnglish = chatWords.translateEnglish;
|
|
24
|
+
/**
|
|
25
|
+
* Checks a page's `messages` against the chat's catalog without showing anything: a key that does not exist (with the
|
|
26
|
+
* nearest real one), a value that is not text, a template that does not parse, or one that asks for a value the message
|
|
27
|
+
* is never given. An empty list means every message will be used. For a test or a build step of the page.
|
|
28
|
+
*/
|
|
29
|
+
export function checkChatMessages(messages) {
|
|
30
|
+
return findMessageProblems(CHAT_MESSAGES, messages);
|
|
31
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every word the chat shows to the person using it, in English: the one place to read them, and the keys a page can
|
|
3
|
+
* replace with the `messages` of the chat.
|
|
4
|
+
*
|
|
5
|
+
* A message is plain text. `{name}` is a value the chat puts in; `{count, plural, one {# file} other {# files}}` picks
|
|
6
|
+
* the form that fits a number in the page's language. `\{`, `\}`, `\#` and `\\` write those characters themselves. See
|
|
7
|
+
* `@widgetic/design-system/i18n` for the whole format.
|
|
8
|
+
*
|
|
9
|
+
* Keys are grouped by where the words appear. A key that is left out of a page's `messages` keeps the English text below,
|
|
10
|
+
* so a language can be added a screen at a time.
|
|
11
|
+
*
|
|
12
|
+
* Words that are NOT here, on purpose:
|
|
13
|
+
* - what the assistant says: its replies, the failures the generation service reports and the names of files are shown as
|
|
14
|
+
* they arrive, in the language they were written in;
|
|
15
|
+
* - the lines the host saves into a conversation in English ("Restored from Version 3", "Code generation failed"):
|
|
16
|
+
* the API keeps them in English; the host's `storedLineLabel` (the widget creator's `conversationLineLabel`) says them
|
|
17
|
+
* in the page's language when they are drawn. The chat still matches commits on the English stored text.
|
|
18
|
+
* - the labels of the host: the version labels ("Version 4") are made by the page that gives them to the chat.
|
|
19
|
+
*/
|
|
20
|
+
export declare const CHAT_MESSAGES: {
|
|
21
|
+
/** What the chat is attached to, in a sentence ("Ask a question about your frame"). */
|
|
22
|
+
readonly 'chat.contextType.frame': "frame";
|
|
23
|
+
readonly 'chat.contextType.text': "text";
|
|
24
|
+
readonly 'chat.contextType.image': "image";
|
|
25
|
+
readonly 'chat.contextType.document': "document";
|
|
26
|
+
readonly 'chat.contextType.canvas': "canvas";
|
|
27
|
+
/** The line under a chat's title: "frame chat". The kind of thing comes from the messages above. */
|
|
28
|
+
readonly 'chat.header.typeChat': "{type} chat";
|
|
29
|
+
readonly 'chat.header.switchConversation': "Switch conversation";
|
|
30
|
+
readonly 'chat.header.conversations': "Conversations";
|
|
31
|
+
readonly 'chat.header.new': "New";
|
|
32
|
+
/** The name of a conversation that has none. */
|
|
33
|
+
readonly 'chat.header.untitled': "Untitled";
|
|
34
|
+
readonly 'chat.header.newConversationTitle': "New conversation";
|
|
35
|
+
readonly 'chat.header.newConversation': "Start new conversation";
|
|
36
|
+
readonly 'chat.header.close': "Close chat";
|
|
37
|
+
/** The name of the button that expands a chat that is shown as a small card. */
|
|
38
|
+
readonly 'chat.contextPreview.expand': "Expand {name} chat context";
|
|
39
|
+
readonly 'chat.conversation.defaultTitle': "Chat about {name}";
|
|
40
|
+
readonly 'chat.messages.startTitle': "Start a conversation";
|
|
41
|
+
readonly 'chat.messages.startHint': "Ask a question about your {type} to get started.";
|
|
42
|
+
readonly 'chat.messages.loadingHistory': "Loading chat history...";
|
|
43
|
+
/** Said while the assistant works on an answer. */
|
|
44
|
+
readonly 'chat.messages.thinking': "Assistant is thinking...";
|
|
45
|
+
/** The mark on the turn of the version that is open now, and the line that explains it. */
|
|
46
|
+
readonly 'chat.messages.viewing': "You are here";
|
|
47
|
+
readonly 'chat.messages.viewingTitle': "This is the version you are looking at";
|
|
48
|
+
readonly 'chat.messages.attachmentMissingTitle': "Attachment not available";
|
|
49
|
+
readonly 'chat.messages.attachmentMissingLabel': "Missing file attachment";
|
|
50
|
+
readonly 'chat.messages.attachmentMissingCaption': "Attachment not saved. Re-attach with Upload, then Retry.";
|
|
51
|
+
readonly 'chat.messages.retry': "Retry";
|
|
52
|
+
readonly 'chat.messages.retryPromptTitle': "Run this prompt again as its own message. The sketch stays with the model, not on the bubble.";
|
|
53
|
+
readonly 'chat.messages.retryLastTitle': "Retry the last user prompt (same generation request)";
|
|
54
|
+
readonly 'chat.messages.upgrade': "Upgrade";
|
|
55
|
+
readonly 'chat.messages.upgradeTitle': "Open plans and billing";
|
|
56
|
+
/** Under a prompt: the short id of the commit it made. */
|
|
57
|
+
readonly 'chat.messages.commitId': "(commit id: {id})";
|
|
58
|
+
readonly 'chat.messages.restore': "Restore Checkpoint";
|
|
59
|
+
readonly 'chat.messages.restoreTitle': "Restore widget code to this prompt's commit";
|
|
60
|
+
readonly 'chat.messages.alreadyHead': "This checkpoint is already HEAD";
|
|
61
|
+
readonly 'chat.messages.showSuggestions': "Show suggestions";
|
|
62
|
+
/**
|
|
63
|
+
* Versions are named "Version 4" between the page and the chat, and in the lines the chat saves ("Restored from Version
|
|
64
|
+
* 4"): the chat reads the number out of those words. It says them again in the page's language with these three.
|
|
65
|
+
* `{number}` is the number of the version, `{label}` the name of the version the restore came from.
|
|
66
|
+
*/
|
|
67
|
+
readonly 'chat.messages.version': "Version {number}";
|
|
68
|
+
readonly 'chat.messages.restoredFrom': "Restored from {label}";
|
|
69
|
+
readonly 'chat.messages.previousVersion': "a previous version";
|
|
70
|
+
readonly 'chat.suggestions.title.frame': "Suggested actions for this widget";
|
|
71
|
+
readonly 'chat.suggestions.title.text': "Suggested text improvements";
|
|
72
|
+
readonly 'chat.suggestions.title.image': "Suggested image analysis";
|
|
73
|
+
readonly 'chat.suggestions.title.document': "Suggested document actions";
|
|
74
|
+
readonly 'chat.suggestions.title.other': "Suggested questions";
|
|
75
|
+
readonly 'chat.suggestions.hide': "Hide suggestions";
|
|
76
|
+
/** The ideas for a widget: tapping one sends it as the person's own message. */
|
|
77
|
+
readonly 'chat.suggestions.frame.generateCode': "Generate code from this design";
|
|
78
|
+
readonly 'chat.suggestions.frame.improveLayout': "Suggest improvements for this layout";
|
|
79
|
+
readonly 'chat.suggestions.frame.addInteractivity': "Add interactive functionality";
|
|
80
|
+
readonly 'chat.suggestions.frame.makeResponsive': "Make this responsive for mobile";
|
|
81
|
+
readonly 'chat.suggestions.frame.addAnimations': "Add animations and transitions";
|
|
82
|
+
readonly 'chat.suggestions.text.improveWriting': "Help improve this writing";
|
|
83
|
+
readonly 'chat.suggestions.text.checkGrammar': "Check grammar and style";
|
|
84
|
+
readonly 'chat.suggestions.text.alternativePhrasing': "Suggest alternative phrasing";
|
|
85
|
+
readonly 'chat.suggestions.text.summarize': "Summarize this content";
|
|
86
|
+
readonly 'chat.suggestions.text.expand': "Expand on this topic";
|
|
87
|
+
readonly 'chat.suggestions.image.describe': "Describe what you see in this image";
|
|
88
|
+
readonly 'chat.suggestions.image.altText': "Generate alt text for accessibility";
|
|
89
|
+
readonly 'chat.suggestions.image.improveDesign': "Suggest design improvements";
|
|
90
|
+
readonly 'chat.suggestions.image.toCode': "Convert image to code";
|
|
91
|
+
readonly 'chat.suggestions.image.extractText': "Extract text from this image";
|
|
92
|
+
readonly 'chat.suggestions.document.summarize': "Summarize this document";
|
|
93
|
+
readonly 'chat.suggestions.document.keyPoints': "Extract key points";
|
|
94
|
+
readonly 'chat.suggestions.document.checkErrors': "Check for errors or inconsistencies";
|
|
95
|
+
readonly 'chat.suggestions.document.improve': "Suggest improvements";
|
|
96
|
+
readonly 'chat.suggestions.document.outline': "Create an outline";
|
|
97
|
+
readonly 'chat.suggestions.other.ask': "Ask a question about this content";
|
|
98
|
+
readonly 'chat.suggestions.other.improve': "Get suggestions for improvement";
|
|
99
|
+
readonly 'chat.suggestions.other.explain': "Explain what you see here";
|
|
100
|
+
readonly 'chat.suggestions.other.understand': "Help me understand this better";
|
|
101
|
+
readonly 'chat.suggestions.other.options': "What can I do with this?";
|
|
102
|
+
readonly 'chat.input.placeholder': "Type your message...";
|
|
103
|
+
readonly 'chat.input.stop': "Stop generation";
|
|
104
|
+
readonly 'chat.input.sending': "Sending message...";
|
|
105
|
+
readonly 'chat.input.send': "Send message";
|
|
106
|
+
readonly 'chat.actions.screenshot': "Screenshot";
|
|
107
|
+
readonly 'chat.actions.screenshotTitle': "Take Screenshot";
|
|
108
|
+
readonly 'chat.actions.screenshotLabel': "Take screenshot of current content";
|
|
109
|
+
readonly 'chat.actions.record': "Record";
|
|
110
|
+
readonly 'chat.actions.stop': "Stop";
|
|
111
|
+
readonly 'chat.actions.startRecordingTitle': "Start Recording";
|
|
112
|
+
readonly 'chat.actions.stopRecordingTitle': "Stop Recording";
|
|
113
|
+
readonly 'chat.actions.startRecordingLabel': "Start recording";
|
|
114
|
+
readonly 'chat.actions.stopRecordingLabel': "Stop recording";
|
|
115
|
+
readonly 'chat.actions.upload': "Upload";
|
|
116
|
+
readonly 'chat.actions.uploadTitle': "Upload File";
|
|
117
|
+
readonly 'chat.actions.uploadLabel': "Upload file";
|
|
118
|
+
readonly 'chat.actions.complete': "Complete";
|
|
119
|
+
readonly 'chat.actions.completed': "Completed";
|
|
120
|
+
readonly 'chat.actions.markCompleteTitle': "Mark this chat as done. You can still send messages and iterate on the widget.";
|
|
121
|
+
readonly 'chat.actions.markActiveTitle': "Mark as Active — you can keep iterating either way";
|
|
122
|
+
readonly 'chat.actions.markCompleteLabel': "Mark conversation as complete";
|
|
123
|
+
readonly 'chat.actions.markActiveLabel': "Mark conversation as active";
|
|
124
|
+
readonly 'chat.resize.label': "Resize messages area";
|
|
125
|
+
readonly 'chat.resize.title': "Drag to resize messages area";
|
|
126
|
+
readonly 'chat.attachment.alt': "Attachment";
|
|
127
|
+
/** The name of a file when it has none. */
|
|
128
|
+
readonly 'chat.attachment.untitled': "Untitled";
|
|
129
|
+
/** The name a file is given in the small list of attachments when it has none. */
|
|
130
|
+
readonly 'chat.attachment.fileFallback': "File";
|
|
131
|
+
/** What a picture of a typed message is called when its file has no name. */
|
|
132
|
+
readonly 'chat.attachment.namelessAlt': "attachment";
|
|
133
|
+
readonly 'chat.attachment.previewAlt': "Attachment preview";
|
|
134
|
+
readonly 'chat.attachment.pdfTitle': "PDF Document";
|
|
135
|
+
readonly 'chat.attachment.noVideo': "Your browser does not support video playback.";
|
|
136
|
+
readonly 'chat.attachment.view': "Click to view {name}";
|
|
137
|
+
readonly 'chat.attachment.viewFile': "Click to view file";
|
|
138
|
+
readonly 'chat.attachment.more': "{count, plural, one {+# more file} other {+# more files}}";
|
|
139
|
+
readonly 'chat.attachment.remove': "Remove attachment";
|
|
140
|
+
readonly 'chat.attachment.close': "Close";
|
|
141
|
+
/** The size of a file, from bytes to gigabytes: `{size}` is the number, written the way the language writes numbers ("1.5", "1,5"). */
|
|
142
|
+
readonly 'chat.size.bytes': "{size} B";
|
|
143
|
+
readonly 'chat.size.kb': "{size} KB";
|
|
144
|
+
readonly 'chat.size.mb': "{size} MB";
|
|
145
|
+
readonly 'chat.size.gb': "{size} GB";
|
|
146
|
+
readonly 'chat.code.copy': "Copy";
|
|
147
|
+
readonly 'chat.code.copyTitle': "Copy code";
|
|
148
|
+
readonly 'chat.code.copied': "Copied!";
|
|
149
|
+
readonly 'chat.status.active': "Active";
|
|
150
|
+
readonly 'chat.status.completed': "Completed";
|
|
151
|
+
readonly 'chat.status.processing': "Processing...";
|
|
152
|
+
readonly 'chat.status.error': "Error";
|
|
153
|
+
readonly 'chat.status.messageCount': "{count, plural, one {(# message)} other {(# messages)}}";
|
|
154
|
+
readonly 'chat.error.dismiss': "Dismiss";
|
|
155
|
+
readonly 'chat.error.retryLoad': "Retry load history";
|
|
156
|
+
readonly 'chat.error.loadHistory': "Could not load chat history.";
|
|
157
|
+
readonly 'chat.error.initialize': "Failed to initialize chat. Please try again.";
|
|
158
|
+
readonly 'chat.error.loadConversations': "Failed to load conversations.";
|
|
159
|
+
readonly 'chat.error.loadConversation': "Failed to load conversation.";
|
|
160
|
+
readonly 'chat.error.sendMessage': "Failed to send message. Please try again.";
|
|
161
|
+
readonly 'chat.error.sendSuggestion': "Failed to send the selected suggestion. Please try again.";
|
|
162
|
+
readonly 'chat.error.screenshotUnavailable': "Screenshot capture failed — no preview available.";
|
|
163
|
+
readonly 'chat.error.screenshotFailed': "Failed to capture screenshot";
|
|
164
|
+
readonly 'chat.error.screenshotActionFailed': "Screenshot action failed. Please try again.";
|
|
165
|
+
readonly 'chat.error.recordingStartFailed': "Failed to start recording";
|
|
166
|
+
readonly 'chat.error.recordingStopFailed': "Failed to stop recording";
|
|
167
|
+
readonly 'chat.error.recordingActionFailed': "Recording action failed. Please try again.";
|
|
168
|
+
readonly 'chat.error.actionFailed': "The action failed. Please try again.";
|
|
169
|
+
readonly 'chat.error.statusUpdateFailed': "Failed to update conversation status";
|
|
170
|
+
readonly 'chat.error.restoreFailed': "Failed to restore checkpoint. Please try again.";
|
|
171
|
+
};
|
|
172
|
+
/** The name of one message. */
|
|
173
|
+
export type ChatMessageKey = keyof typeof CHAT_MESSAGES;
|