@widgetic/chat 0.1.35 → 0.1.37
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 -6
- package/dist/components/ActionBar.svelte +8 -0
- package/dist/components/Chat.svelte +120 -106
- package/dist/components/Chat.svelte.d.ts +19 -1
- package/dist/components/ChatComposer.svelte +166 -0
- package/dist/components/ChatComposer.svelte.d.ts +30 -0
- package/dist/components/ChatMessages.svelte +483 -393
- package/dist/components/ChatMessages.svelte.d.ts +16 -6
- package/dist/components/IconButton.svelte +125 -0
- package/dist/components/IconButton.svelte.d.ts +22 -0
- package/dist/components/MessageActions.svelte +48 -0
- package/dist/components/MessageActions.svelte.d.ts +13 -0
- package/dist/components/PanelChatHeader.svelte +79 -0
- package/dist/components/PanelChatHeader.svelte.d.ts +19 -0
- package/dist/components/PanelFollowUpSuggestions.svelte +34 -0
- package/dist/components/PanelFollowUpSuggestions.svelte.d.ts +8 -0
- package/dist/components/PanelSuggestionButtons.svelte +60 -0
- package/dist/components/PanelSuggestionButtons.svelte.d.ts +10 -0
- package/dist/components/SuggestionButtons.svelte +11 -163
- package/dist/i18n/index.d.ts +1 -1
- package/dist/i18n/index.js +1 -1
- package/dist/i18n/messages.d.ts +54 -13
- package/dist/i18n/messages.js +54 -13
- package/dist/i18n/suggestions.d.ts +6 -0
- package/dist/i18n/suggestions.js +24 -0
- package/dist/types/message.d.ts +7 -0
- package/dist/utils/generationActivity.d.ts +12 -0
- package/dist/utils/generationActivity.js +47 -0
- package/dist/utils/generationPlan.d.ts +32 -0
- package/dist/utils/generationPlan.js +89 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/messageActions.d.ts +54 -0
- package/dist/utils/messageActions.js +104 -0
- package/package.json +3 -3
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { AttachmentInput } from '../types/attachment.js';
|
|
3
|
+
import { useChatLanguage } from '../i18n/language.js';
|
|
4
|
+
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
5
|
+
import { Composer, IconButton } from '@widgetic/design-system/components/chat/index';
|
|
6
|
+
import { chatLog } from '../utils/logger.js';
|
|
7
|
+
|
|
8
|
+
const { t } = useChatLanguage();
|
|
9
|
+
const textDirection = useTextDirection();
|
|
10
|
+
|
|
11
|
+
export type ComposerModelOption = { id: string; label: string };
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
value?: string;
|
|
15
|
+
isSending?: boolean;
|
|
16
|
+
isGenerating?: boolean;
|
|
17
|
+
canSendWithoutText?: boolean;
|
|
18
|
+
placeholder?: string;
|
|
19
|
+
class?: string;
|
|
20
|
+
style?: string;
|
|
21
|
+
models?: ComposerModelOption[];
|
|
22
|
+
selectedModelId?: string | null;
|
|
23
|
+
onSelectModel?: (modelId: string) => void;
|
|
24
|
+
onSend: (content: string, attachments?: AttachmentInput[]) => void;
|
|
25
|
+
onStop?: () => void;
|
|
26
|
+
onInputChange?: (text: string) => void;
|
|
27
|
+
onFilesDropped?: (files: File[]) => void;
|
|
28
|
+
/** Opens the file picker. The "+" of the toolbar is drawn only when the page can attach files. */
|
|
29
|
+
onAttach?: () => void;
|
|
30
|
+
/** Figma side-panel composer: no top border on the shell; DS Composer keeps its own border. */
|
|
31
|
+
panelLayout?: boolean;
|
|
32
|
+
/** Figma panel composer (65:31): arrow-up send icon instead of paper-plane. */
|
|
33
|
+
sendIcon?: 'send' | 'arrow-up';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let {
|
|
37
|
+
value = $bindable(),
|
|
38
|
+
isSending = false,
|
|
39
|
+
isGenerating = false,
|
|
40
|
+
canSendWithoutText = false,
|
|
41
|
+
placeholder,
|
|
42
|
+
class: className = '',
|
|
43
|
+
style = '',
|
|
44
|
+
models = [],
|
|
45
|
+
selectedModelId = null,
|
|
46
|
+
onSelectModel,
|
|
47
|
+
onSend,
|
|
48
|
+
onStop,
|
|
49
|
+
onInputChange,
|
|
50
|
+
onFilesDropped,
|
|
51
|
+
onAttach,
|
|
52
|
+
panelLayout = false,
|
|
53
|
+
sendIcon = 'send',
|
|
54
|
+
}: Props = $props();
|
|
55
|
+
|
|
56
|
+
const composerSendIcon = $derived(panelLayout ? 'arrow-up' : sendIcon);
|
|
57
|
+
|
|
58
|
+
let isFileDragOver = $state(false);
|
|
59
|
+
|
|
60
|
+
const busy = $derived(isGenerating || isSending);
|
|
61
|
+
const allowEmptySend = $derived(canSendWithoutText);
|
|
62
|
+
|
|
63
|
+
function isOsFileDrag(event: DragEvent): boolean {
|
|
64
|
+
return !!event.dataTransfer?.types?.includes('Files');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function handleFileDragEnter(event: DragEvent) {
|
|
68
|
+
if (!isOsFileDrag(event)) return;
|
|
69
|
+
event.preventDefault();
|
|
70
|
+
isFileDragOver = true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function handleFileDragOver(event: DragEvent) {
|
|
74
|
+
if (!isOsFileDrag(event)) return;
|
|
75
|
+
event.preventDefault();
|
|
76
|
+
if (event.dataTransfer) event.dataTransfer.dropEffect = 'copy';
|
|
77
|
+
isFileDragOver = true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function handleFileDragLeave(event: DragEvent) {
|
|
81
|
+
if (!isOsFileDrag(event)) return;
|
|
82
|
+
const related = event.relatedTarget as Node | null;
|
|
83
|
+
if (related && (event.currentTarget as HTMLElement).contains(related)) return;
|
|
84
|
+
isFileDragOver = false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function handleFileDrop(event: DragEvent) {
|
|
88
|
+
if (!isOsFileDrag(event)) return;
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
event.stopPropagation();
|
|
91
|
+
isFileDragOver = false;
|
|
92
|
+
const droppedFiles = Array.from(event.dataTransfer?.files || []).filter((file) => file && file.size > 0);
|
|
93
|
+
if (droppedFiles.length === 0) return;
|
|
94
|
+
chatLog('[ChatComposer] OS files dropped:', droppedFiles.length);
|
|
95
|
+
onFilesDropped?.(droppedFiles);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function handleComposerSend(text: string) {
|
|
99
|
+
const trimmed = text.trim();
|
|
100
|
+
if (!trimmed && !allowEmptySend) return;
|
|
101
|
+
if (isSending && !isGenerating) return;
|
|
102
|
+
onSend(trimmed, undefined);
|
|
103
|
+
}
|
|
104
|
+
</script>
|
|
105
|
+
|
|
106
|
+
<!-- Figma: Composer toolbar, left side: attach ("+"), then the mode. -->
|
|
107
|
+
{#snippet attachControl()}
|
|
108
|
+
{#if onAttach}
|
|
109
|
+
<IconButton
|
|
110
|
+
variant="ghost"
|
|
111
|
+
data-testid="chat-composer-attach"
|
|
112
|
+
label={$t('chat.actions.uploadLabel')}
|
|
113
|
+
disabled={isSending && !isGenerating}
|
|
114
|
+
onclick={() => onAttach?.()}
|
|
115
|
+
>
|
|
116
|
+
<svg
|
|
117
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
118
|
+
class="size-4 stroke-2"
|
|
119
|
+
viewBox="0 0 24 24"
|
|
120
|
+
fill="none"
|
|
121
|
+
stroke="currentColor"
|
|
122
|
+
stroke-linecap="round"
|
|
123
|
+
stroke-linejoin="round"
|
|
124
|
+
aria-hidden="true"
|
|
125
|
+
>
|
|
126
|
+
<path d="M12 5l0 14" />
|
|
127
|
+
<path d="M5 12l14 0" />
|
|
128
|
+
</svg>
|
|
129
|
+
</IconButton>
|
|
130
|
+
{/if}
|
|
131
|
+
{/snippet}
|
|
132
|
+
|
|
133
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
134
|
+
<div
|
|
135
|
+
class="chat-composer-shell border-border bg-background shrink-0 {panelLayout ? '' : 'border-t'} {className} {isFileDragOver
|
|
136
|
+
? 'outline-primary outline-2 outline-dashed'
|
|
137
|
+
: ''}"
|
|
138
|
+
{style}
|
|
139
|
+
ondragenter={handleFileDragEnter}
|
|
140
|
+
ondragover={handleFileDragOver}
|
|
141
|
+
ondragleave={handleFileDragLeave}
|
|
142
|
+
ondrop={handleFileDrop}
|
|
143
|
+
>
|
|
144
|
+
<Composer
|
|
145
|
+
class={panelLayout ? 'w-full max-w-full' : 'rounded-none border-0'}
|
|
146
|
+
sendIcon={composerSendIcon}
|
|
147
|
+
bind:value
|
|
148
|
+
busy={isGenerating}
|
|
149
|
+
disabled={isSending && !isGenerating}
|
|
150
|
+
allowEmpty={allowEmptySend}
|
|
151
|
+
placeholder={placeholder ?? $t('chat.input.placeholder')}
|
|
152
|
+
{models}
|
|
153
|
+
{selectedModelId}
|
|
154
|
+
onSelectModel={onSelectModel}
|
|
155
|
+
messages={{
|
|
156
|
+
send: $t('chat.input.send'),
|
|
157
|
+
stop: $t('chat.input.stop'),
|
|
158
|
+
attach: $t('chat.actions.upload'),
|
|
159
|
+
characterLimit: $t('chat.input.tooLong')
|
|
160
|
+
}}
|
|
161
|
+
assistantLabel={$t('chat.composer.assistant')}
|
|
162
|
+
onSend={handleComposerSend}
|
|
163
|
+
onStop={() => onStop?.()}
|
|
164
|
+
leading={attachControl}
|
|
165
|
+
/>
|
|
166
|
+
</div>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AttachmentInput } from '../types/attachment.js';
|
|
2
|
+
export type ComposerModelOption = {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
};
|
|
6
|
+
interface Props {
|
|
7
|
+
value?: string;
|
|
8
|
+
isSending?: boolean;
|
|
9
|
+
isGenerating?: boolean;
|
|
10
|
+
canSendWithoutText?: boolean;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
class?: string;
|
|
13
|
+
style?: string;
|
|
14
|
+
models?: ComposerModelOption[];
|
|
15
|
+
selectedModelId?: string | null;
|
|
16
|
+
onSelectModel?: (modelId: string) => void;
|
|
17
|
+
onSend: (content: string, attachments?: AttachmentInput[]) => void;
|
|
18
|
+
onStop?: () => void;
|
|
19
|
+
onInputChange?: (text: string) => void;
|
|
20
|
+
onFilesDropped?: (files: File[]) => void;
|
|
21
|
+
/** Opens the file picker. The "+" of the toolbar is drawn only when the page can attach files. */
|
|
22
|
+
onAttach?: () => void;
|
|
23
|
+
/** Figma side-panel composer: no top border on the shell; DS Composer keeps its own border. */
|
|
24
|
+
panelLayout?: boolean;
|
|
25
|
+
/** Figma panel composer (65:31): arrow-up send icon instead of paper-plane. */
|
|
26
|
+
sendIcon?: 'send' | 'arrow-up';
|
|
27
|
+
}
|
|
28
|
+
declare const ChatComposer: import("svelte").Component<Props, {}, "value">;
|
|
29
|
+
type ChatComposer = ReturnType<typeof ChatComposer>;
|
|
30
|
+
export default ChatComposer;
|