@kitnai/chat 0.1.0
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/LICENSE +21 -0
- package/README.md +314 -0
- package/dist/bash-InADTalH.js +6 -0
- package/dist/core-AYMC6_lb.js +5874 -0
- package/dist/engine-javascript-vq0WuIJl.js +2643 -0
- package/dist/github-dark-dimmed-DUshB20C.js +4 -0
- package/dist/github-light-JYsPkUQd.js +4 -0
- package/dist/javascript-C25yR2R2.js +6 -0
- package/dist/json-DxJze_jm.js +6 -0
- package/dist/kitn-chat.es.js +6632 -0
- package/dist/tsx-B8rCNbgL.js +6 -0
- package/dist/typescript-RycA9KXf.js +6 -0
- package/package.json +80 -0
- package/src/components/attachments.stories.tsx +304 -0
- package/src/components/attachments.tsx +394 -0
- package/src/components/chain-of-thought.stories.tsx +212 -0
- package/src/components/chain-of-thought.tsx +139 -0
- package/src/components/chat-container.stories.tsx +188 -0
- package/src/components/chat-container.tsx +78 -0
- package/src/components/chat-scope-picker.tsx +47 -0
- package/src/components/checkpoint.stories.tsx +103 -0
- package/src/components/checkpoint.tsx +81 -0
- package/src/components/code-block.stories.tsx +151 -0
- package/src/components/code-block.tsx +99 -0
- package/src/components/context.stories.tsx +180 -0
- package/src/components/context.tsx +323 -0
- package/src/components/conversation-item.stories.tsx +126 -0
- package/src/components/conversation-item.tsx +18 -0
- package/src/components/conversation-list.stories.tsx +134 -0
- package/src/components/conversation-list.tsx +100 -0
- package/src/components/empty.stories.tsx +435 -0
- package/src/components/empty.tsx +166 -0
- package/src/components/feedback-bar.stories.tsx +101 -0
- package/src/components/feedback-bar.tsx +58 -0
- package/src/components/file-upload.stories.tsx +157 -0
- package/src/components/file-upload.tsx +161 -0
- package/src/components/image.stories.tsx +90 -0
- package/src/components/image.tsx +67 -0
- package/src/components/loader.stories.tsx +182 -0
- package/src/components/loader.tsx +333 -0
- package/src/components/markdown.stories.tsx +181 -0
- package/src/components/markdown.tsx +81 -0
- package/src/components/message-narrow.stories.tsx +330 -0
- package/src/components/message-skills.stories.tsx +212 -0
- package/src/components/message-skills.tsx +36 -0
- package/src/components/message.stories.tsx +282 -0
- package/src/components/message.tsx +149 -0
- package/src/components/model-switcher.stories.tsx +98 -0
- package/src/components/model-switcher.tsx +36 -0
- package/src/components/prompt-input.stories.tsx +223 -0
- package/src/components/prompt-input.tsx +190 -0
- package/src/components/prompt-suggestion.stories.tsx +143 -0
- package/src/components/prompt-suggestion.tsx +115 -0
- package/src/components/reasoning.stories.tsx +141 -0
- package/src/components/reasoning.tsx +157 -0
- package/src/components/response-stream.tsx +103 -0
- package/src/components/scroll-button.stories.tsx +101 -0
- package/src/components/scroll-button.tsx +33 -0
- package/src/components/slash-command.stories.tsx +164 -0
- package/src/components/slash-command.tsx +223 -0
- package/src/components/source.stories.tsx +125 -0
- package/src/components/source.tsx +129 -0
- package/src/components/text-shimmer.stories.tsx +88 -0
- package/src/components/text-shimmer.tsx +37 -0
- package/src/components/thinking-bar.stories.tsx +88 -0
- package/src/components/thinking-bar.tsx +50 -0
- package/src/components/tool.stories.tsx +154 -0
- package/src/components/tool.tsx +173 -0
- package/src/components/voice-input.stories.tsx +84 -0
- package/src/components/voice-input.tsx +103 -0
- package/src/elements/chat-types.ts +14 -0
- package/src/elements/chat.tsx +111 -0
- package/src/elements/compiled.css +2 -0
- package/src/elements/conversation-list.tsx +26 -0
- package/src/elements/css.ts +5 -0
- package/src/elements/default-input.tsx +53 -0
- package/src/elements/define.tsx +54 -0
- package/src/elements/kitn-chat.stories.tsx +105 -0
- package/src/elements/kitn-conversation-list.stories.tsx +177 -0
- package/src/elements/kitn-prompt-input.stories.tsx +123 -0
- package/src/elements/prompt-input.tsx +39 -0
- package/src/elements/register.ts +9 -0
- package/src/elements/styles.css +12 -0
- package/src/index.ts +128 -0
- package/src/primitives/chat-config.tsx +76 -0
- package/src/primitives/highlighter.ts +150 -0
- package/src/primitives/use-auto-resize.ts +31 -0
- package/src/primitives/use-stick-to-bottom.ts +43 -0
- package/src/primitives/use-text-stream.ts +112 -0
- package/src/primitives/use-voice-recorder.ts +50 -0
- package/src/stories/chat-panel-layout.stories.tsx +144 -0
- package/src/stories/chat-scene.tsx +570 -0
- package/src/stories/checkpoint-restore.stories.tsx +224 -0
- package/src/stories/context-usage.stories.tsx +155 -0
- package/src/stories/conversation-with-reasoning.stories.tsx +151 -0
- package/src/stories/conversation-with-sources.stories.tsx +165 -0
- package/src/stories/docs/GettingStarted.mdx +76 -0
- package/src/stories/docs/Installation.mdx +48 -0
- package/src/stories/docs/Integrations.mdx +110 -0
- package/src/stories/docs/Introduction.mdx +29 -0
- package/src/stories/docs/Theming.mdx +87 -0
- package/src/stories/docs/theme-editor/canvas.tsx +32 -0
- package/src/stories/docs/theme-editor/inspector.tsx +66 -0
- package/src/stories/docs/theme-editor/presets.test.ts +32 -0
- package/src/stories/docs/theme-editor/presets.ts +64 -0
- package/src/stories/docs/theme-editor/theme-css.test.ts +19 -0
- package/src/stories/docs/theme-editor/theme-css.ts +15 -0
- package/src/stories/docs/theme-editor/theme-editor.tsx +145 -0
- package/src/stories/docs/theme-tokens.tsx +174 -0
- package/src/stories/full-chat.stories.tsx +18 -0
- package/src/stories/message-actions.stories.tsx +167 -0
- package/src/stories/prompt-input-variants.stories.tsx +179 -0
- package/src/stories/streaming-response.stories.tsx +234 -0
- package/src/stories/theme-editor.stories.tsx +16 -0
- package/src/stories/token-reference.stories.tsx +18 -0
- package/src/types.ts +41 -0
- package/src/ui/avatar.stories.tsx +104 -0
- package/src/ui/avatar.tsx +23 -0
- package/src/ui/badge.stories.tsx +87 -0
- package/src/ui/badge.tsx +21 -0
- package/src/ui/button.stories.tsx +146 -0
- package/src/ui/button.tsx +37 -0
- package/src/ui/collapsible.tsx +14 -0
- package/src/ui/dialog.tsx +21 -0
- package/src/ui/dropdown.tsx +26 -0
- package/src/ui/hover-card.tsx +48 -0
- package/src/ui/resizable.stories.tsx +171 -0
- package/src/ui/resizable.tsx +219 -0
- package/src/ui/scroll-area.tsx +13 -0
- package/src/ui/separator.stories.tsx +82 -0
- package/src/ui/separator.tsx +10 -0
- package/src/ui/skeleton.stories.tsx +338 -0
- package/src/ui/skeleton.tsx +16 -0
- package/src/ui/textarea.tsx +21 -0
- package/src/ui/tooltip.stories.tsx +75 -0
- package/src/ui/tooltip.tsx +22 -0
- package/src/utils/cn.ts +6 -0
- package/theme.css +115 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "storybook-solidjs-vite";
|
|
2
|
+
import { MessageSkills } from "./message-skills";
|
|
3
|
+
import { Message, MessageContent, MessageActions } from "./message";
|
|
4
|
+
import { ChatConfig } from "../primitives/chat-config";
|
|
5
|
+
import { Copy, ThumbsUp, ThumbsDown } from "lucide-solid";
|
|
6
|
+
|
|
7
|
+
const meta = {
|
|
8
|
+
title: "Components/MessageSkills",
|
|
9
|
+
component: MessageSkills,
|
|
10
|
+
tags: ["autodocs"],
|
|
11
|
+
parameters: {
|
|
12
|
+
layout: "padded",
|
|
13
|
+
docs: {
|
|
14
|
+
controls: { exclude: ["use:eventListener"] },
|
|
15
|
+
description: {
|
|
16
|
+
component: [
|
|
17
|
+
"A row of small badges that label which **skills** were active when a message was generated.",
|
|
18
|
+
"**When to use:** above an assistant message whose response was shaped by one or more skills (e.g. `Concise`, `ELI5`). Renders nothing when the `skills` array is empty.",
|
|
19
|
+
"**How to use:** pass a `skills` array of `{ id, name }`; each `name` is shown as a badge. Add `class` (e.g. `mb-1`) to space it from the message body.",
|
|
20
|
+
"**Placement:** directly above `MessageContent` inside an assistant `Message`.",
|
|
21
|
+
].join("\n\n"),
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
argTypes: {
|
|
26
|
+
skills: {
|
|
27
|
+
control: "object",
|
|
28
|
+
description: "Active skills to display as badges. Each is `{ id, name }`.",
|
|
29
|
+
},
|
|
30
|
+
class: {
|
|
31
|
+
control: "text",
|
|
32
|
+
description: "Extra classes for the badge row container.",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
args: {
|
|
36
|
+
skills: [
|
|
37
|
+
{ id: "1", name: "Concise" },
|
|
38
|
+
{ id: "2", name: "ELI5" },
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
render: (args) => <MessageSkills {...args} />,
|
|
42
|
+
} satisfies Meta<typeof MessageSkills>;
|
|
43
|
+
|
|
44
|
+
export default meta;
|
|
45
|
+
type Story = StoryObj<typeof meta>;
|
|
46
|
+
|
|
47
|
+
const IMPORT = `import { MessageSkills } from '@kitnai/chat';`;
|
|
48
|
+
const src = (code: string) => ({
|
|
49
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: "tsx" } } },
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/** Interactive playground — edit the `skills` array to see the badges update. */
|
|
53
|
+
export const Playground: Story = {
|
|
54
|
+
...src(`<MessageSkills skills={[{ id: '1', name: 'Concise' }, { id: '2', name: 'ELI5' }]} />`),
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** A single active skill. */
|
|
58
|
+
export const SingleSkill: Story = {
|
|
59
|
+
args: { skills: [{ id: "1", name: "Caveman" }] },
|
|
60
|
+
...src(`<MessageSkills skills={[{ id: '1', name: 'Caveman' }]} />`),
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** Several active skills wrap onto multiple lines if needed. */
|
|
64
|
+
export const MultipleSkills: Story = {
|
|
65
|
+
args: {
|
|
66
|
+
skills: [
|
|
67
|
+
{ id: "1", name: "Concise" },
|
|
68
|
+
{ id: "2", name: "ELI5" },
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
...src(`<MessageSkills
|
|
72
|
+
skills={[
|
|
73
|
+
{ id: '1', name: 'Concise' },
|
|
74
|
+
{ id: '2', name: 'ELI5' },
|
|
75
|
+
]}
|
|
76
|
+
/>`),
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/** Empty array — the component renders nothing. */
|
|
80
|
+
export const NoSkills: Story = {
|
|
81
|
+
args: { skills: [] },
|
|
82
|
+
...src(`<MessageSkills skills={[]} />`),
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/** Composed above an assistant message body (showcase — not driven by controls). */
|
|
86
|
+
export const InAssistantMessage: Story = {
|
|
87
|
+
name: "In Assistant Message",
|
|
88
|
+
render: () => (
|
|
89
|
+
<ChatConfig proseSize="sm">
|
|
90
|
+
<div class="max-w-md space-y-4">
|
|
91
|
+
<Message class="flex-col !gap-0">
|
|
92
|
+
<MessageSkills skills={[{ id: "1", name: "Caveman" }]} class="mb-1" />
|
|
93
|
+
<MessageContent markdown class="bg-transparent p-0 pt-1.5">
|
|
94
|
+
{"Bug in auth middleware. Token expiry check use `<` not `<=`. Fix: update comparison operator in `validateToken()`."}
|
|
95
|
+
</MessageContent>
|
|
96
|
+
<MessageActions class="[&>button]:p-1 [&>button]:rounded [&>button]:text-foreground/60 [&>button]:hover:text-foreground [&>button]:transition-colors">
|
|
97
|
+
<button>
|
|
98
|
+
<Copy size={14} />
|
|
99
|
+
</button>
|
|
100
|
+
<button>
|
|
101
|
+
<ThumbsUp size={14} />
|
|
102
|
+
</button>
|
|
103
|
+
<button>
|
|
104
|
+
<ThumbsDown size={14} />
|
|
105
|
+
</button>
|
|
106
|
+
</MessageActions>
|
|
107
|
+
</Message>
|
|
108
|
+
|
|
109
|
+
<Message class="flex-col !gap-0">
|
|
110
|
+
<MessageContent markdown class="bg-transparent p-0 pt-1.5">
|
|
111
|
+
The authentication middleware validates JWT tokens by checking the
|
|
112
|
+
expiration timestamp. There's a bug in the comparison operator that
|
|
113
|
+
causes tokens to be accepted even when they've just expired.
|
|
114
|
+
</MessageContent>
|
|
115
|
+
<MessageActions class="[&>button]:p-1 [&>button]:rounded [&>button]:text-foreground/60 [&>button]:hover:text-foreground [&>button]:transition-colors">
|
|
116
|
+
<button>
|
|
117
|
+
<Copy size={14} />
|
|
118
|
+
</button>
|
|
119
|
+
<button>
|
|
120
|
+
<ThumbsUp size={14} />
|
|
121
|
+
</button>
|
|
122
|
+
<button>
|
|
123
|
+
<ThumbsDown size={14} />
|
|
124
|
+
</button>
|
|
125
|
+
</MessageActions>
|
|
126
|
+
</Message>
|
|
127
|
+
</div>
|
|
128
|
+
</ChatConfig>
|
|
129
|
+
),
|
|
130
|
+
...src(`<Message class="flex-col !gap-0">
|
|
131
|
+
<MessageSkills skills={[{ id: '1', name: 'Caveman' }]} class="mb-1" />
|
|
132
|
+
<MessageContent markdown class="bg-transparent p-0 pt-1.5">
|
|
133
|
+
{assistantText}
|
|
134
|
+
</MessageContent>
|
|
135
|
+
</Message>`),
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/** Skills across a multi-turn flow (showcase). */
|
|
139
|
+
export const InConversation: Story = {
|
|
140
|
+
name: "In Conversation Flow",
|
|
141
|
+
render: () => (
|
|
142
|
+
<ChatConfig proseSize="sm">
|
|
143
|
+
<div class="max-w-md space-y-4">
|
|
144
|
+
<Message class="group flex-col items-end !gap-0">
|
|
145
|
+
<MessageContent class="bg-muted text-primary max-w-[85%] rounded-xl px-4 py-2 mr-1">
|
|
146
|
+
What is the main topic of this video?
|
|
147
|
+
</MessageContent>
|
|
148
|
+
</Message>
|
|
149
|
+
|
|
150
|
+
<Message class="flex-col !gap-0">
|
|
151
|
+
<MessageContent markdown class="bg-transparent p-0 pt-1.5">
|
|
152
|
+
The video covers advanced React patterns including compound
|
|
153
|
+
components, render props, and custom hooks for state management.
|
|
154
|
+
</MessageContent>
|
|
155
|
+
<MessageActions class="[&>button]:p-1 [&>button]:rounded [&>button]:text-foreground/60 [&>button]:hover:text-foreground [&>button]:transition-colors">
|
|
156
|
+
<button><Copy size={14} /></button>
|
|
157
|
+
</MessageActions>
|
|
158
|
+
</Message>
|
|
159
|
+
|
|
160
|
+
<Message class="group flex-col items-end !gap-0">
|
|
161
|
+
<MessageContent class="bg-muted text-primary max-w-[85%] rounded-xl px-4 py-2 mr-1">
|
|
162
|
+
Can you explain that more simply?
|
|
163
|
+
</MessageContent>
|
|
164
|
+
</Message>
|
|
165
|
+
|
|
166
|
+
<Message class="flex-col !gap-0">
|
|
167
|
+
<MessageSkills skills={[{ id: "1", name: "ELI5" }]} class="mb-1" />
|
|
168
|
+
<MessageContent markdown class="bg-transparent p-0 pt-1.5">
|
|
169
|
+
Think of React patterns like different ways to build with LEGO.
|
|
170
|
+
Some ways make it easier to change pieces later, some ways make
|
|
171
|
+
it easier to share pieces between different builds.
|
|
172
|
+
</MessageContent>
|
|
173
|
+
<MessageActions class="[&>button]:p-1 [&>button]:rounded [&>button]:text-foreground/60 [&>button]:hover:text-foreground [&>button]:transition-colors">
|
|
174
|
+
<button><Copy size={14} /></button>
|
|
175
|
+
</MessageActions>
|
|
176
|
+
</Message>
|
|
177
|
+
|
|
178
|
+
<Message class="group flex-col items-end !gap-0">
|
|
179
|
+
<MessageContent class="bg-muted text-primary max-w-[85%] rounded-xl px-4 py-2 mr-1">
|
|
180
|
+
Now give me the technical details
|
|
181
|
+
</MessageContent>
|
|
182
|
+
</Message>
|
|
183
|
+
|
|
184
|
+
<Message class="flex-col !gap-0">
|
|
185
|
+
<MessageSkills
|
|
186
|
+
skills={[
|
|
187
|
+
{ id: "1", name: "Detailed" },
|
|
188
|
+
{ id: "2", name: "Concise" },
|
|
189
|
+
]}
|
|
190
|
+
class="mb-1"
|
|
191
|
+
/>
|
|
192
|
+
<MessageContent markdown class="bg-transparent p-0 pt-1.5">
|
|
193
|
+
{`**Compound Components**: Share implicit state via React Context. Parent owns state, children consume it.
|
|
194
|
+
|
|
195
|
+
**Render Props**: Pass a function as a prop that returns JSX. Enables inversion of control.
|
|
196
|
+
|
|
197
|
+
**Custom Hooks**: Extract stateful logic into reusable functions prefixed with \`use\`.`}
|
|
198
|
+
</MessageContent>
|
|
199
|
+
<MessageActions class="[&>button]:p-1 [&>button]:rounded [&>button]:text-foreground/60 [&>button]:hover:text-foreground [&>button]:transition-colors">
|
|
200
|
+
<button><Copy size={14} /></button>
|
|
201
|
+
</MessageActions>
|
|
202
|
+
</Message>
|
|
203
|
+
</div>
|
|
204
|
+
</ChatConfig>
|
|
205
|
+
),
|
|
206
|
+
...src(`<Message class="flex-col !gap-0">
|
|
207
|
+
<MessageSkills skills={[{ id: '1', name: 'Detailed' }, { id: '2', name: 'Concise' }]} class="mb-1" />
|
|
208
|
+
<MessageContent markdown class="bg-transparent p-0 pt-1.5">
|
|
209
|
+
{assistantText}
|
|
210
|
+
</MessageContent>
|
|
211
|
+
</Message>`),
|
|
212
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Show, For, type JSX, splitProps } from "solid-js";
|
|
2
|
+
import { cn } from "../utils/cn";
|
|
3
|
+
|
|
4
|
+
// --- MessageSkills ---
|
|
5
|
+
|
|
6
|
+
export interface Skill {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface MessageSkillsProps {
|
|
12
|
+
skills: Skill[];
|
|
13
|
+
class?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Displays skill badges above a message to indicate which skills
|
|
18
|
+
* were active when the message was generated.
|
|
19
|
+
*/
|
|
20
|
+
function MessageSkills(props: MessageSkillsProps) {
|
|
21
|
+
return (
|
|
22
|
+
<Show when={props.skills.length > 0}>
|
|
23
|
+
<div class={cn("flex items-center gap-1 flex-wrap", props.class)}>
|
|
24
|
+
<For each={props.skills}>
|
|
25
|
+
{(skill) => (
|
|
26
|
+
<span class="inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-violet-400/10 text-violet-400">
|
|
27
|
+
{skill.name}
|
|
28
|
+
</span>
|
|
29
|
+
)}
|
|
30
|
+
</For>
|
|
31
|
+
</div>
|
|
32
|
+
</Show>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { MessageSkills };
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { Message, MessageAvatar, MessageContent, MessageActions } from './message';
|
|
3
|
+
import { Button } from '../ui/button';
|
|
4
|
+
import { Copy, ThumbsUp, ThumbsDown, RefreshCw, Pencil } from 'lucide-solid';
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'Components/Message',
|
|
8
|
+
component: Message,
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
parameters: {
|
|
11
|
+
layout: 'padded',
|
|
12
|
+
docs: {
|
|
13
|
+
controls: { exclude: ['use:eventListener'] },
|
|
14
|
+
description: {
|
|
15
|
+
component: [
|
|
16
|
+
'A horizontal message row that composes an optional `MessageAvatar`, a `MessageContent` body (plain or markdown), and an optional `MessageActions` toolbar.',
|
|
17
|
+
'**When to use:** rendering any chat turn — user or assistant. Use a bubble + right alignment for user turns, and an avatar + transparent content for assistant turns.',
|
|
18
|
+
'**How to use:** wrap the parts in `<Message>`. Add `MessageAvatar` for the speaker, `MessageContent` for the text (set `markdown` to render markdown), and `MessageActions` for hover actions. Layout (alignment, bubble) is controlled via `class`.',
|
|
19
|
+
'**Placement:** inside a `ChatContainer`/scroll region, stacked vertically as the conversation transcript.',
|
|
20
|
+
].join('\n\n'),
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
argTypes: {
|
|
25
|
+
children: {
|
|
26
|
+
control: false,
|
|
27
|
+
description: 'The composed message parts (avatar, content, actions).',
|
|
28
|
+
},
|
|
29
|
+
class: {
|
|
30
|
+
control: 'text',
|
|
31
|
+
description: 'Layout classes — e.g. `flex flex-col items-end` for right-aligned user turns.',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
args: {
|
|
35
|
+
class: '',
|
|
36
|
+
},
|
|
37
|
+
render: (args) => (
|
|
38
|
+
<div class="max-w-2xl">
|
|
39
|
+
<Message {...args}>
|
|
40
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
41
|
+
<MessageContent>
|
|
42
|
+
I can help with a variety of tasks: answering questions, providing
|
|
43
|
+
information, assisting with coding, and generating creative content.
|
|
44
|
+
What would you like help with today?
|
|
45
|
+
</MessageContent>
|
|
46
|
+
</Message>
|
|
47
|
+
</div>
|
|
48
|
+
),
|
|
49
|
+
} satisfies Meta<typeof Message>;
|
|
50
|
+
|
|
51
|
+
export default meta;
|
|
52
|
+
type Story = StoryObj<typeof meta>;
|
|
53
|
+
|
|
54
|
+
const IMPORT = `import { Message, MessageAvatar, MessageContent, MessageActions } from '@kitnai/chat';`;
|
|
55
|
+
const src = (code: string) => ({
|
|
56
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/** Interactive playground — an assistant turn; tweak `class` to change layout. */
|
|
60
|
+
export const Playground: Story = {
|
|
61
|
+
...src(`<Message>
|
|
62
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
63
|
+
<MessageContent>I can help with a variety of tasks...</MessageContent>
|
|
64
|
+
</Message>`),
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** A user turn — right-aligned bubble, no avatar. */
|
|
68
|
+
export const UserMessage: Story = {
|
|
69
|
+
render: () => (
|
|
70
|
+
<div class="max-w-2xl">
|
|
71
|
+
<Message class="flex flex-col items-end">
|
|
72
|
+
<MessageContent class="bg-muted text-primary max-w-[85%] rounded-3xl px-5 py-2.5">
|
|
73
|
+
Hello! How can I help you today?
|
|
74
|
+
</MessageContent>
|
|
75
|
+
</Message>
|
|
76
|
+
</div>
|
|
77
|
+
),
|
|
78
|
+
...src(`<Message class="flex flex-col items-end">
|
|
79
|
+
<MessageContent class="bg-muted text-primary max-w-[85%] rounded-3xl px-5 py-2.5">
|
|
80
|
+
Hello! How can I help you today?
|
|
81
|
+
</MessageContent>
|
|
82
|
+
</Message>`),
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/** An assistant turn — avatar plus a secondary-background content block. */
|
|
86
|
+
export const AssistantMessage: Story = {
|
|
87
|
+
render: () => (
|
|
88
|
+
<div class="max-w-2xl">
|
|
89
|
+
<Message>
|
|
90
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
91
|
+
<MessageContent>
|
|
92
|
+
I can help with a variety of tasks: answering questions, providing information,
|
|
93
|
+
assisting with coding, generating creative content. What would you like help with today?
|
|
94
|
+
</MessageContent>
|
|
95
|
+
</Message>
|
|
96
|
+
</div>
|
|
97
|
+
),
|
|
98
|
+
...src(`<Message>
|
|
99
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
100
|
+
<MessageContent>I can help with a variety of tasks...</MessageContent>
|
|
101
|
+
</Message>`),
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/** Assistant turn with a transparent, flush content block (no bubble). */
|
|
105
|
+
export const AssistantNoBg: Story = {
|
|
106
|
+
name: 'Assistant (No Background)',
|
|
107
|
+
render: () => (
|
|
108
|
+
<div class="max-w-2xl">
|
|
109
|
+
<Message>
|
|
110
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
111
|
+
<MessageContent class="bg-transparent p-0">
|
|
112
|
+
I can help with a variety of tasks: answering questions, providing information,
|
|
113
|
+
assisting with coding, generating creative content. What would you like help with today?
|
|
114
|
+
</MessageContent>
|
|
115
|
+
</Message>
|
|
116
|
+
</div>
|
|
117
|
+
),
|
|
118
|
+
...src(`<Message>
|
|
119
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
120
|
+
<MessageContent class="bg-transparent p-0">...</MessageContent>
|
|
121
|
+
</Message>`),
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/** User bubble with hover-revealed edit/copy actions. */
|
|
125
|
+
export const UserAlignedRight: Story = {
|
|
126
|
+
name: 'User (Right-Aligned)',
|
|
127
|
+
render: () => (
|
|
128
|
+
<div class="max-w-2xl">
|
|
129
|
+
<Message class="flex flex-col items-end">
|
|
130
|
+
<div class="group flex flex-col items-end gap-1">
|
|
131
|
+
<MessageContent class="bg-muted text-primary max-w-[85%] rounded-3xl px-5 py-2.5">
|
|
132
|
+
Can you explain how SolidJS reactivity differs from React hooks?
|
|
133
|
+
</MessageContent>
|
|
134
|
+
<MessageActions class="flex gap-0 opacity-0 transition-opacity duration-150 group-hover:opacity-100">
|
|
135
|
+
<Button variant="ghost" size="icon-sm" class="rounded-full">
|
|
136
|
+
<Pencil class="size-3.5" />
|
|
137
|
+
</Button>
|
|
138
|
+
<Button variant="ghost" size="icon-sm" class="rounded-full">
|
|
139
|
+
<Copy class="size-3.5" />
|
|
140
|
+
</Button>
|
|
141
|
+
</MessageActions>
|
|
142
|
+
</div>
|
|
143
|
+
</Message>
|
|
144
|
+
</div>
|
|
145
|
+
),
|
|
146
|
+
...src(`<Message class="flex flex-col items-end">
|
|
147
|
+
<div class="group flex flex-col items-end gap-1">
|
|
148
|
+
<MessageContent class="bg-muted text-primary max-w-[85%] rounded-3xl px-5 py-2.5">
|
|
149
|
+
Can you explain how SolidJS reactivity differs from React hooks?
|
|
150
|
+
</MessageContent>
|
|
151
|
+
<MessageActions class="opacity-0 group-hover:opacity-100">
|
|
152
|
+
<Button variant="ghost" size="icon-sm"><Pencil class="size-3.5" /></Button>
|
|
153
|
+
<Button variant="ghost" size="icon-sm"><Copy class="size-3.5" /></Button>
|
|
154
|
+
</MessageActions>
|
|
155
|
+
</div>
|
|
156
|
+
</Message>`),
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/** Markdown body — set `markdown` on `MessageContent` and pass a markdown string. */
|
|
160
|
+
export const MarkdownMessage: Story = {
|
|
161
|
+
render: () => (
|
|
162
|
+
<div class="max-w-2xl">
|
|
163
|
+
<Message>
|
|
164
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
165
|
+
<MessageContent markdown class="bg-transparent p-0">
|
|
166
|
+
{`Here's a **bold** statement with some \`inline code\` and a list:
|
|
167
|
+
|
|
168
|
+
- First item
|
|
169
|
+
- Second item
|
|
170
|
+
- Third item
|
|
171
|
+
|
|
172
|
+
And a code block:
|
|
173
|
+
|
|
174
|
+
\`\`\`typescript
|
|
175
|
+
const greeting = "Hello, world!";
|
|
176
|
+
console.log(greeting);
|
|
177
|
+
\`\`\``}
|
|
178
|
+
</MessageContent>
|
|
179
|
+
</Message>
|
|
180
|
+
</div>
|
|
181
|
+
),
|
|
182
|
+
...src(`<Message>
|
|
183
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
184
|
+
<MessageContent markdown class="bg-transparent p-0">
|
|
185
|
+
{markdownString}
|
|
186
|
+
</MessageContent>
|
|
187
|
+
</Message>`),
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/** Assistant turn with a hover action row (copy / feedback / regenerate). */
|
|
191
|
+
export const WithActions: Story = {
|
|
192
|
+
render: () => (
|
|
193
|
+
<div class="max-w-2xl">
|
|
194
|
+
<Message>
|
|
195
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
196
|
+
<div class="group flex w-full flex-col gap-0">
|
|
197
|
+
<MessageContent class="bg-transparent p-0">
|
|
198
|
+
Here is a response with hover actions below it.
|
|
199
|
+
</MessageContent>
|
|
200
|
+
<MessageActions class="-ml-2.5 flex gap-0 opacity-0 transition-opacity duration-150 group-hover:opacity-100">
|
|
201
|
+
<Button variant="ghost" size="icon-sm" class="rounded-full">
|
|
202
|
+
<Copy class="size-3.5" />
|
|
203
|
+
</Button>
|
|
204
|
+
<Button variant="ghost" size="icon-sm" class="rounded-full">
|
|
205
|
+
<ThumbsUp class="size-3.5" />
|
|
206
|
+
</Button>
|
|
207
|
+
<Button variant="ghost" size="icon-sm" class="rounded-full">
|
|
208
|
+
<ThumbsDown class="size-3.5" />
|
|
209
|
+
</Button>
|
|
210
|
+
<Button variant="ghost" size="icon-sm" class="rounded-full">
|
|
211
|
+
<RefreshCw class="size-3.5" />
|
|
212
|
+
</Button>
|
|
213
|
+
</MessageActions>
|
|
214
|
+
</div>
|
|
215
|
+
</Message>
|
|
216
|
+
</div>
|
|
217
|
+
),
|
|
218
|
+
...src(`<Message>
|
|
219
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
220
|
+
<div class="group flex w-full flex-col gap-0">
|
|
221
|
+
<MessageContent class="bg-transparent p-0">Here is a response...</MessageContent>
|
|
222
|
+
<MessageActions class="opacity-0 group-hover:opacity-100">
|
|
223
|
+
<Button variant="ghost" size="icon-sm"><Copy class="size-3.5" /></Button>
|
|
224
|
+
<Button variant="ghost" size="icon-sm"><ThumbsUp class="size-3.5" /></Button>
|
|
225
|
+
<Button variant="ghost" size="icon-sm"><ThumbsDown class="size-3.5" /></Button>
|
|
226
|
+
<Button variant="ghost" size="icon-sm"><RefreshCw class="size-3.5" /></Button>
|
|
227
|
+
</MessageActions>
|
|
228
|
+
</div>
|
|
229
|
+
</Message>`),
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
/** A user + assistant pair showing both layouts together (showcase). */
|
|
233
|
+
export const Conversation: Story = {
|
|
234
|
+
render: () => (
|
|
235
|
+
<div class="max-w-2xl space-y-4">
|
|
236
|
+
<Message class="flex flex-col items-end">
|
|
237
|
+
<MessageContent class="bg-muted text-primary max-w-[85%] rounded-3xl px-5 py-2.5">
|
|
238
|
+
What is TypeScript?
|
|
239
|
+
</MessageContent>
|
|
240
|
+
</Message>
|
|
241
|
+
|
|
242
|
+
<Message>
|
|
243
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
244
|
+
<div class="group flex w-full flex-col gap-0">
|
|
245
|
+
<MessageContent markdown class="bg-transparent p-0">
|
|
246
|
+
{`**TypeScript** is a strongly typed programming language that builds on JavaScript. It adds optional static type checking and other features like interfaces, enums, and generics.
|
|
247
|
+
|
|
248
|
+
Key benefits:
|
|
249
|
+
- Catches errors at compile time
|
|
250
|
+
- Better IDE support and autocompletion
|
|
251
|
+
- Makes large codebases more maintainable`}
|
|
252
|
+
</MessageContent>
|
|
253
|
+
<MessageActions class="-ml-2.5 flex gap-0 opacity-0 transition-opacity duration-150 group-hover:opacity-100">
|
|
254
|
+
<Button variant="ghost" size="icon-sm" class="rounded-full">
|
|
255
|
+
<Copy class="size-3.5" />
|
|
256
|
+
</Button>
|
|
257
|
+
<Button variant="ghost" size="icon-sm" class="rounded-full">
|
|
258
|
+
<ThumbsUp class="size-3.5" />
|
|
259
|
+
</Button>
|
|
260
|
+
<Button variant="ghost" size="icon-sm" class="rounded-full">
|
|
261
|
+
<ThumbsDown class="size-3.5" />
|
|
262
|
+
</Button>
|
|
263
|
+
<Button variant="ghost" size="icon-sm" class="rounded-full">
|
|
264
|
+
<RefreshCw class="size-3.5" />
|
|
265
|
+
</Button>
|
|
266
|
+
</MessageActions>
|
|
267
|
+
</div>
|
|
268
|
+
</Message>
|
|
269
|
+
</div>
|
|
270
|
+
),
|
|
271
|
+
...src(`<div class="space-y-4">
|
|
272
|
+
<Message class="flex flex-col items-end">
|
|
273
|
+
<MessageContent class="bg-muted text-primary rounded-3xl px-5 py-2.5">
|
|
274
|
+
What is TypeScript?
|
|
275
|
+
</MessageContent>
|
|
276
|
+
</Message>
|
|
277
|
+
<Message>
|
|
278
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
279
|
+
<MessageContent markdown class="bg-transparent p-0">{answerMarkdown}</MessageContent>
|
|
280
|
+
</Message>
|
|
281
|
+
</div>`),
|
|
282
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { type JSX, createSignal, splitProps, Show } from "solid-js";
|
|
2
|
+
import { Copy, Check } from "lucide-solid";
|
|
3
|
+
import { cn } from "../utils/cn";
|
|
4
|
+
import { Markdown } from "./markdown";
|
|
5
|
+
import { useChatConfig, textClass } from "../primitives/chat-config";
|
|
6
|
+
|
|
7
|
+
// --- Message ---
|
|
8
|
+
|
|
9
|
+
export interface MessageProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|
10
|
+
children: JSX.Element;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function Message(props: MessageProps) {
|
|
14
|
+
const [local, rest] = splitProps(props, ["children", "class"]);
|
|
15
|
+
return (
|
|
16
|
+
<div class={cn("flex items-start gap-3", local.class)} {...rest}>
|
|
17
|
+
{local.children}
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// --- MessageAvatar ---
|
|
23
|
+
|
|
24
|
+
export interface MessageAvatarProps {
|
|
25
|
+
src: string;
|
|
26
|
+
alt: string;
|
|
27
|
+
fallback?: string;
|
|
28
|
+
class?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function MessageAvatar(props: MessageAvatarProps) {
|
|
32
|
+
return (
|
|
33
|
+
<div
|
|
34
|
+
class={cn("h-8 w-8 shrink-0 overflow-hidden rounded-full", props.class)}
|
|
35
|
+
>
|
|
36
|
+
<Show
|
|
37
|
+
when={props.src}
|
|
38
|
+
fallback={
|
|
39
|
+
<Show when={props.fallback}>
|
|
40
|
+
<div class="flex h-full w-full items-center justify-center bg-muted text-xs font-medium text-muted-foreground">
|
|
41
|
+
{props.fallback}
|
|
42
|
+
</div>
|
|
43
|
+
</Show>
|
|
44
|
+
}
|
|
45
|
+
>
|
|
46
|
+
<img
|
|
47
|
+
src={props.src}
|
|
48
|
+
alt={props.alt}
|
|
49
|
+
class="h-full w-full object-cover"
|
|
50
|
+
/>
|
|
51
|
+
</Show>
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// --- MessageContent ---
|
|
57
|
+
|
|
58
|
+
export interface MessageContentProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|
59
|
+
children: JSX.Element | string;
|
|
60
|
+
markdown?: boolean;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function MessageContent(props: MessageContentProps) {
|
|
64
|
+
const [local, rest] = splitProps(props, ["children", "markdown", "class"]);
|
|
65
|
+
const config = useChatConfig();
|
|
66
|
+
const classNames = () =>
|
|
67
|
+
cn(
|
|
68
|
+
"min-w-0 rounded-lg p-2 text-foreground bg-secondary max-w-none break-words whitespace-normal",
|
|
69
|
+
textClass(config.proseSize()),
|
|
70
|
+
local.class,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<Show
|
|
75
|
+
when={local.markdown}
|
|
76
|
+
fallback={
|
|
77
|
+
<div class={classNames()} {...rest}>
|
|
78
|
+
{local.children}
|
|
79
|
+
</div>
|
|
80
|
+
}
|
|
81
|
+
>
|
|
82
|
+
<Markdown content={local.children as string} class={classNames()} />
|
|
83
|
+
</Show>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// --- MessageActions ---
|
|
88
|
+
|
|
89
|
+
export interface MessageActionsProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|
90
|
+
children: JSX.Element;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function MessageActions(props: MessageActionsProps) {
|
|
94
|
+
const [local, rest] = splitProps(props, ["children", "class"]);
|
|
95
|
+
return (
|
|
96
|
+
<div
|
|
97
|
+
class={cn(
|
|
98
|
+
"flex items-center gap-0.5 mt-0.5",
|
|
99
|
+
local.class,
|
|
100
|
+
)}
|
|
101
|
+
{...rest}
|
|
102
|
+
>
|
|
103
|
+
{local.children}
|
|
104
|
+
</div>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// --- MessageAction ---
|
|
109
|
+
|
|
110
|
+
export interface MessageActionProps {
|
|
111
|
+
tooltip: string;
|
|
112
|
+
children: JSX.Element;
|
|
113
|
+
side?: "top" | "bottom" | "left" | "right";
|
|
114
|
+
class?: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function MessageAction(props: MessageActionProps) {
|
|
118
|
+
return <>{props.children}</>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// --- MessageCopyButton ---
|
|
122
|
+
|
|
123
|
+
export interface MessageCopyButtonProps {
|
|
124
|
+
content: string;
|
|
125
|
+
size?: number;
|
|
126
|
+
class?: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function MessageCopyButton(props: MessageCopyButtonProps) {
|
|
130
|
+
const [copied, setCopied] = createSignal(false);
|
|
131
|
+
const iconSize = () => props.size ?? 14;
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<button
|
|
135
|
+
class={props.class}
|
|
136
|
+
onClick={() => {
|
|
137
|
+
navigator.clipboard.writeText(props.content);
|
|
138
|
+
setCopied(true);
|
|
139
|
+
setTimeout(() => setCopied(false), 2000);
|
|
140
|
+
}}
|
|
141
|
+
>
|
|
142
|
+
<Show when={copied()} fallback={<Copy size={iconSize()} />}>
|
|
143
|
+
<Check size={iconSize()} class="text-emerald-400" />
|
|
144
|
+
</Show>
|
|
145
|
+
</button>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export { Message, MessageAvatar, MessageContent, MessageActions, MessageAction, MessageCopyButton };
|