@kitn.ai/ui 0.14.1
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 +394 -0
- package/dist/bash-InADTalH.js +1 -0
- package/dist/core-AYMC6_lb.js +12 -0
- package/dist/css-M7EaDHN_.js +1 -0
- package/dist/custom-elements.json +4739 -0
- package/dist/engine-javascript-vq0WuIJl.js +141 -0
- package/dist/github-dark-dimmed-DUshB20C.js +1 -0
- package/dist/github-light-JYsPkUQd.js +1 -0
- package/dist/host-embed.d.ts +33 -0
- package/dist/html-CPZ3oZQ7.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/javascript-C25yR2R2.js +1 -0
- package/dist/json-DxJze_jm.js +1 -0
- package/dist/kitn-chat-provider.d.ts +2 -0
- package/dist/kitn-chat-provider.es.js +240 -0
- package/dist/kitn-chat.es.js +77 -0
- package/dist/llms/llms-full.txt +1018 -0
- package/dist/llms/llms.txt +104 -0
- package/dist/origin.d.ts +5 -0
- package/dist/provider-runtime.d.ts +27 -0
- package/dist/schemas/card-envelope.schema.json +14 -0
- package/dist/schemas/card-event.schema.json +12 -0
- package/dist/schemas/choice.schema.json +70 -0
- package/dist/schemas/confirm.schema.json +65 -0
- package/dist/schemas/embed.schema.json +65 -0
- package/dist/schemas/form.result.schema.json +7 -0
- package/dist/schemas/form.schema.json +33 -0
- package/dist/schemas/link.schema.json +56 -0
- package/dist/schemas/tasks.result.schema.json +16 -0
- package/dist/schemas/tasks.schema.json +78 -0
- package/dist/svelte--5p79yCD.js +1 -0
- package/dist/theme.tokens.css +176 -0
- package/dist/tsx-B8rCNbgL.js +1 -0
- package/dist/typescript-RycA9KXf.js +1 -0
- package/dist/validate.d.ts +4 -0
- package/dist/version.d.ts +4 -0
- package/dist/vue-BmIZj4XD.js +1 -0
- package/dist/wire.d.ts +53 -0
- package/frameworks/react/index.tsx +948 -0
- package/frameworks/react/runtime.tsx +94 -0
- package/llms-full.txt +1018 -0
- package/llms.txt +104 -0
- package/package.json +141 -0
- package/src/components/artifact.stories.tsx +138 -0
- package/src/components/artifact.tsx +743 -0
- package/src/components/attachments.stories.tsx +303 -0
- package/src/components/attachments.test.tsx +64 -0
- package/src/components/attachments.tsx +399 -0
- package/src/components/card-fallback.tsx +28 -0
- package/src/components/card-renderer.tsx +52 -0
- package/src/components/card.tsx +110 -0
- package/src/components/chain-of-thought.stories.tsx +211 -0
- package/src/components/chain-of-thought.tsx +139 -0
- package/src/components/chat-container.stories.tsx +187 -0
- package/src/components/chat-container.tsx +82 -0
- package/src/components/chat-scope-picker.tsx +47 -0
- package/src/components/chat-thread.test.tsx +58 -0
- package/src/components/chat-thread.tsx +249 -0
- package/src/components/checkpoint.stories.tsx +102 -0
- package/src/components/checkpoint.tsx +88 -0
- package/src/components/choice-card.tsx +569 -0
- package/src/components/code-block.stories.tsx +150 -0
- package/src/components/code-block.tsx +105 -0
- package/src/components/component-meta.json +3735 -0
- package/src/components/confirm-card.stories.tsx +74 -0
- package/src/components/confirm-card.tsx +315 -0
- package/src/components/context.stories.tsx +229 -0
- package/src/components/context.test.tsx +133 -0
- package/src/components/context.tsx +363 -0
- package/src/components/conversation-item.stories.tsx +125 -0
- package/src/components/conversation-item.tsx +16 -0
- package/src/components/conversation-list.stories.tsx +133 -0
- package/src/components/conversation-list.tsx +101 -0
- package/src/components/default-input.test.tsx +111 -0
- package/src/components/embed.tsx +196 -0
- package/src/components/empty.stories.tsx +434 -0
- package/src/components/empty.tsx +166 -0
- package/src/components/feedback-bar.stories.tsx +138 -0
- package/src/components/feedback-bar.test.tsx +103 -0
- package/src/components/feedback-bar.tsx +166 -0
- package/src/components/file-tree.stories.tsx +73 -0
- package/src/components/file-tree.tsx +383 -0
- package/src/components/file-upload.stories.tsx +156 -0
- package/src/components/file-upload.tsx +161 -0
- package/src/components/form-widgets.tsx +461 -0
- package/src/components/form.tsx +873 -0
- package/src/components/image.stories.tsx +89 -0
- package/src/components/image.tsx +67 -0
- package/src/components/link-preview.tsx +194 -0
- package/src/components/loader.stories.tsx +181 -0
- package/src/components/loader.tsx +333 -0
- package/src/components/markdown.stories.tsx +180 -0
- package/src/components/markdown.tsx +81 -0
- package/src/components/message-action-bar.test.tsx +128 -0
- package/src/components/message-narrow.stories.tsx +329 -0
- package/src/components/message-skills.stories.tsx +211 -0
- package/src/components/message-skills.tsx +36 -0
- package/src/components/message.stories.tsx +281 -0
- package/src/components/message.tsx +227 -0
- package/src/components/model-switcher.stories.tsx +123 -0
- package/src/components/model-switcher.test.tsx +65 -0
- package/src/components/model-switcher.tsx +87 -0
- package/src/components/prompt-input.stories.tsx +222 -0
- package/src/components/prompt-input.tsx +211 -0
- package/src/components/prompt-suggestion.stories.tsx +142 -0
- package/src/components/prompt-suggestion.tsx +115 -0
- package/src/components/reasoning.stories.tsx +140 -0
- package/src/components/reasoning.tsx +156 -0
- package/src/components/resizable.test.tsx +226 -0
- package/src/components/response-stream.tsx +103 -0
- package/src/components/scroll-button.stories.tsx +100 -0
- package/src/components/scroll-button.tsx +34 -0
- package/src/components/slash-command.stories.tsx +163 -0
- package/src/components/slash-command.tsx +232 -0
- package/src/components/source-list.test.tsx +152 -0
- package/src/components/source.stories.tsx +124 -0
- package/src/components/source.tsx +129 -0
- package/src/components/tasks-card.stories.tsx +78 -0
- package/src/components/tasks-card.tsx +432 -0
- package/src/components/text-shimmer.stories.tsx +87 -0
- package/src/components/text-shimmer.tsx +37 -0
- package/src/components/thinking-bar.stories.tsx +87 -0
- package/src/components/thinking-bar.tsx +50 -0
- package/src/components/tool.stories.tsx +153 -0
- package/src/components/tool.tsx +184 -0
- package/src/components/use-card-resolution.ts +28 -0
- package/src/components/voice-input.stories.tsx +83 -0
- package/src/components/voice-input.tsx +107 -0
- package/src/elements/artifact.stories.tsx +506 -0
- package/src/elements/artifact.tsx +137 -0
- package/src/elements/attachments.stories.tsx +190 -0
- package/src/elements/attachments.tsx +136 -0
- package/src/elements/card.stories.tsx +113 -0
- package/src/elements/card.tsx +40 -0
- package/src/elements/cards.stories.tsx +59 -0
- package/src/elements/cards.tsx +97 -0
- package/src/elements/catalog.stories.tsx +491 -0
- package/src/elements/chain-of-thought.declarative.test.tsx +153 -0
- package/src/elements/chain-of-thought.stories.tsx +113 -0
- package/src/elements/chain-of-thought.tsx +92 -0
- package/src/elements/chat-scope-picker.stories.tsx +73 -0
- package/src/elements/chat-scope-picker.tsx +36 -0
- package/src/elements/chat-types.ts +42 -0
- package/src/elements/chat-workspace.stories.tsx +288 -0
- package/src/elements/chat-workspace.tsx +161 -0
- package/src/elements/chat.stories.tsx +151 -0
- package/src/elements/chat.tsx +80 -0
- package/src/elements/checkpoint.stories.tsx +72 -0
- package/src/elements/checkpoint.tsx +47 -0
- package/src/elements/choice.stories.tsx +240 -0
- package/src/elements/choice.tsx +48 -0
- package/src/elements/code-block.stories.tsx +83 -0
- package/src/elements/code-block.tsx +42 -0
- package/src/elements/compiled.css +2 -0
- package/src/elements/composed-shell.stories.tsx +316 -0
- package/src/elements/confirm-card.stories.tsx +227 -0
- package/src/elements/confirm-card.tsx +51 -0
- package/src/elements/context-meter.stories.tsx +151 -0
- package/src/elements/context-meter.tsx +121 -0
- package/src/elements/conversation-list.declarative.test.tsx +137 -0
- package/src/elements/conversation-list.stories.tsx +243 -0
- package/src/elements/conversation-list.tsx +80 -0
- package/src/elements/css.ts +5 -0
- package/src/elements/default-input.tsx +247 -0
- package/src/elements/define.tsx +171 -0
- package/src/elements/element-meta.json +3314 -0
- package/src/elements/element-types.d.ts +710 -0
- package/src/elements/embed.stories.tsx +213 -0
- package/src/elements/embed.tsx +35 -0
- package/src/elements/empty.stories.tsx +111 -0
- package/src/elements/empty.tsx +29 -0
- package/src/elements/feedback-bar.stories.tsx +114 -0
- package/src/elements/feedback-bar.tsx +61 -0
- package/src/elements/file-tree.stories.tsx +134 -0
- package/src/elements/file-tree.tsx +52 -0
- package/src/elements/file-upload.stories.tsx +82 -0
- package/src/elements/file-upload.tsx +44 -0
- package/src/elements/form.stories.tsx +248 -0
- package/src/elements/form.tsx +43 -0
- package/src/elements/framework-usage.json +563 -0
- package/src/elements/image.stories.tsx +71 -0
- package/src/elements/image.tsx +32 -0
- package/src/elements/link-preview.stories.tsx +209 -0
- package/src/elements/link-preview.tsx +34 -0
- package/src/elements/loader.stories.tsx +88 -0
- package/src/elements/loader.tsx +25 -0
- package/src/elements/markdown.stories.tsx +76 -0
- package/src/elements/markdown.tsx +38 -0
- package/src/elements/message-skills.declarative.test.tsx +104 -0
- package/src/elements/message-skills.stories.tsx +114 -0
- package/src/elements/message-skills.tsx +85 -0
- package/src/elements/message.stories.tsx +218 -0
- package/src/elements/message.tsx +162 -0
- package/src/elements/model-switcher.declarative.test.tsx +130 -0
- package/src/elements/model-switcher.stories.tsx +198 -0
- package/src/elements/model-switcher.tsx +93 -0
- package/src/elements/popover.stories.tsx +80 -0
- package/src/elements/popover.tsx +59 -0
- package/src/elements/prompt-input-slash-command.test.tsx +128 -0
- package/src/elements/prompt-input-stoppable.test.tsx +88 -0
- package/src/elements/prompt-input-toolbar-actions.test.tsx +120 -0
- package/src/elements/prompt-input.stories.tsx +331 -0
- package/src/elements/prompt-input.tsx +185 -0
- package/src/elements/prompt-suggestions.declarative.test.tsx +164 -0
- package/src/elements/prompt-suggestions.stories.tsx +213 -0
- package/src/elements/prompt-suggestions.tsx +94 -0
- package/src/elements/reasoning.stories.tsx +77 -0
- package/src/elements/reasoning.tsx +50 -0
- package/src/elements/register.ts +56 -0
- package/src/elements/remote.stories.tsx +314 -0
- package/src/elements/remote.tsx +221 -0
- package/src/elements/resizable.d.ts +27 -0
- package/src/elements/resizable.stories.tsx +426 -0
- package/src/elements/resizable.tsx +553 -0
- package/src/elements/response-stream.stories.tsx +79 -0
- package/src/elements/response-stream.tsx +40 -0
- package/src/elements/scroll-button.stories.tsx +202 -0
- package/src/elements/scroll-button.test.tsx +148 -0
- package/src/elements/scroll-button.tsx +126 -0
- package/src/elements/source-list.stories.tsx +143 -0
- package/src/elements/source.stories.tsx +88 -0
- package/src/elements/source.tsx +120 -0
- package/src/elements/styles.css +199 -0
- package/src/elements/switch.stories.tsx +56 -0
- package/src/elements/switch.tsx +43 -0
- package/src/elements/tasks.stories.tsx +237 -0
- package/src/elements/tasks.tsx +46 -0
- package/src/elements/text-shimmer.stories.tsx +64 -0
- package/src/elements/text-shimmer.tsx +28 -0
- package/src/elements/thinking-bar.stories.tsx +72 -0
- package/src/elements/thinking-bar.tsx +34 -0
- package/src/elements/tool.stories.tsx +89 -0
- package/src/elements/tool.tsx +23 -0
- package/src/elements/voice-input.stories.tsx +88 -0
- package/src/elements/voice-input.tsx +41 -0
- package/src/index.ts +253 -0
- package/src/primitives/card-contract.ts +71 -0
- package/src/primitives/card-host.tsx +35 -0
- package/src/primitives/card-registry.tsx +67 -0
- package/src/primitives/card-resolution.ts +36 -0
- package/src/primitives/card-routing.ts +79 -0
- package/src/primitives/card-schemas/card-envelope.schema.json +14 -0
- package/src/primitives/card-schemas/card-event.schema.json +12 -0
- package/src/primitives/card-schemas/choice.schema.json +70 -0
- package/src/primitives/card-schemas/confirm.schema.json +65 -0
- package/src/primitives/card-schemas/embed.schema.json +65 -0
- package/src/primitives/card-schemas/form.result.schema.json +7 -0
- package/src/primitives/card-schemas/form.schema.json +33 -0
- package/src/primitives/card-schemas/link.schema.json +56 -0
- package/src/primitives/card-schemas/tasks.result.schema.json +16 -0
- package/src/primitives/card-schemas/tasks.schema.json +78 -0
- package/src/primitives/card-validate.ts +95 -0
- package/src/primitives/chat-config.tsx +76 -0
- package/src/primitives/controllable.test.ts +47 -0
- package/src/primitives/controllable.ts +21 -0
- package/src/primitives/embed-providers.ts +254 -0
- package/src/primitives/highlighter.ts +157 -0
- package/src/primitives/link-preview.ts +87 -0
- package/src/primitives/pdf-preview.ts +121 -0
- package/src/primitives/use-auto-resize.ts +31 -0
- package/src/primitives/use-resize-observer.ts +12 -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/remote/host-embed.ts +345 -0
- package/src/remote/index.ts +2 -0
- package/src/remote/origin.ts +30 -0
- package/src/remote/provider-runtime.ts +259 -0
- package/src/remote/provider.ts +2 -0
- package/src/remote/validate.ts +22 -0
- package/src/remote/version.ts +12 -0
- package/src/remote/wire.ts +48 -0
- package/src/stories/chat-panel-layout.stories.tsx +145 -0
- package/src/stories/chat-scene.tsx +571 -0
- package/src/stories/checkpoint-restore.stories.tsx +256 -0
- package/src/stories/context-usage.stories.tsx +212 -0
- package/src/stories/conversation-with-reasoning.stories.tsx +182 -0
- package/src/stories/conversation-with-sources.stories.tsx +471 -0
- package/src/stories/docs/Accessibility.mdx +119 -0
- package/src/stories/docs/ChildElements.mdx +269 -0
- package/src/stories/docs/ForAIAgents.mdx +162 -0
- package/src/stories/docs/GettingStarted.mdx +65 -0
- package/src/stories/docs/Installation.mdx +83 -0
- package/src/stories/docs/Introduction.mdx +50 -0
- package/src/stories/docs/SolidJsAdvanced.mdx +17 -0
- package/src/stories/docs/Theming.mdx +85 -0
- package/src/stories/docs/element-controls.ts +121 -0
- package/src/stories/docs/frameworks/Angular.mdx +245 -0
- package/src/stories/docs/frameworks/Html.mdx +227 -0
- package/src/stories/docs/frameworks/Overview.mdx +47 -0
- package/src/stories/docs/frameworks/React.mdx +227 -0
- package/src/stories/docs/frameworks/Solid.mdx +173 -0
- package/src/stories/docs/frameworks/Svelte.mdx +194 -0
- package/src/stories/docs/frameworks/Vue.mdx +238 -0
- package/src/stories/docs/generative-ui-overview.mdx +186 -0
- package/src/stories/docs/recipes/SpeechToText.mdx +7 -0
- package/src/stories/docs/recipes/Streaming.mdx +68 -0
- package/src/stories/docs/recipes/TextToSpeech.mdx +35 -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 +146 -0
- package/src/stories/docs/theme-tokens.tsx +174 -0
- package/src/stories/examples/ChoosingComponents.mdx +106 -0
- package/src/stories/examples/sample-data.ts +79 -0
- package/src/stories/examples/usage/checkpoint-restore.ts +156 -0
- package/src/stories/examples/usage/context-usage.ts +591 -0
- package/src/stories/examples/usage/conversation-with-reasoning.ts +224 -0
- package/src/stories/examples/usage/conversation-with-sources.ts +589 -0
- package/src/stories/examples/usage/empty-state.ts +144 -0
- package/src/stories/examples/usage/full-chat-app.ts +277 -0
- package/src/stories/examples/usage/index.ts +63 -0
- package/src/stories/examples/usage/message-actions.ts +704 -0
- package/src/stories/examples/usage/pattern-centered-conversation.ts +446 -0
- package/src/stories/examples/usage/pattern-chat-panel-layout.ts +442 -0
- package/src/stories/examples/usage/pattern-docked-widget.ts +479 -0
- package/src/stories/examples/usage/prompt-input-variants.ts +1356 -0
- package/src/stories/examples/usage/streaming-response.ts +687 -0
- package/src/stories/examples/usage/types.ts +33 -0
- package/src/stories/full-chat.stories.tsx +18 -0
- package/src/stories/message-actions.stories.tsx +230 -0
- package/src/stories/pattern-centered-conversation.stories.tsx +93 -0
- package/src/stories/pattern-docked-widget.stories.tsx +93 -0
- package/src/stories/pattern-empty-state.stories.tsx +76 -0
- package/src/stories/prompt-input-variants.stories.tsx +456 -0
- package/src/stories/streaming-response.stories.tsx +438 -0
- package/src/stories/theme-editor.stories.tsx +16 -0
- package/src/stories/token-reference.stories.tsx +18 -0
- package/src/stories/typography.stories.tsx +78 -0
- package/src/types.ts +47 -0
- package/src/ui/action-icons.ts +52 -0
- package/src/ui/avatar.stories.tsx +103 -0
- package/src/ui/avatar.tsx +23 -0
- package/src/ui/badge.stories.tsx +86 -0
- package/src/ui/badge.tsx +21 -0
- package/src/ui/button.stories.tsx +145 -0
- package/src/ui/button.tsx +38 -0
- package/src/ui/collapsible.stories.tsx +69 -0
- package/src/ui/collapsible.tsx +125 -0
- package/src/ui/dropdown.stories.tsx +59 -0
- package/src/ui/dropdown.tsx +196 -0
- package/src/ui/hover-card.stories.tsx +77 -0
- package/src/ui/hover-card.test.tsx +30 -0
- package/src/ui/hover-card.tsx +172 -0
- package/src/ui/overlay.stories.tsx +115 -0
- package/src/ui/overlay.tsx +158 -0
- package/src/ui/popover.stories.tsx +81 -0
- package/src/ui/popover.test.tsx +99 -0
- package/src/ui/popover.tsx +92 -0
- package/src/ui/resizable.stories.tsx +236 -0
- package/src/ui/resizable.tsx +576 -0
- package/src/ui/scroll-area.stories.tsx +50 -0
- package/src/ui/scroll-area.tsx +15 -0
- package/src/ui/separator.stories.tsx +81 -0
- package/src/ui/separator.tsx +10 -0
- package/src/ui/skeleton.stories.tsx +337 -0
- package/src/ui/skeleton.tsx +16 -0
- package/src/ui/switch.stories.tsx +51 -0
- package/src/ui/switch.test.tsx +59 -0
- package/src/ui/switch.tsx +62 -0
- package/src/ui/textarea.stories.tsx +76 -0
- package/src/ui/textarea.tsx +21 -0
- package/src/ui/tooltip.stories.tsx +74 -0
- package/src/ui/tooltip.tsx +68 -0
- package/src/utils/cn.ts +24 -0
- package/theme.css +187 -0
|
@@ -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-600 dark:text-violet-400">
|
|
27
|
+
{skill.name}
|
|
28
|
+
</span>
|
|
29
|
+
)}
|
|
30
|
+
</For>
|
|
31
|
+
</div>
|
|
32
|
+
</Show>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { MessageSkills };
|
|
@@ -0,0 +1,281 @@
|
|
|
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
|
+
import { componentDescription } from '../stories/docs/element-controls';
|
|
6
|
+
|
|
7
|
+
const meta = {
|
|
8
|
+
title: 'Solid (Advanced)/Elements/Message',
|
|
9
|
+
component: Message,
|
|
10
|
+
tags: ['autodocs'],
|
|
11
|
+
parameters: {
|
|
12
|
+
layout: 'padded',
|
|
13
|
+
docs: {
|
|
14
|
+
controls: { exclude: ['use:eventListener'] },
|
|
15
|
+
description: componentDescription([
|
|
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
|
+
]),
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
argTypes: {
|
|
24
|
+
children: {
|
|
25
|
+
control: false,
|
|
26
|
+
description: 'The composed message parts (avatar, content, actions).',
|
|
27
|
+
},
|
|
28
|
+
class: {
|
|
29
|
+
control: 'text',
|
|
30
|
+
description: 'Layout classes — e.g. `flex flex-col items-end` for right-aligned user turns.',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
args: {
|
|
34
|
+
class: '',
|
|
35
|
+
},
|
|
36
|
+
render: (args) => (
|
|
37
|
+
<div class="max-w-2xl">
|
|
38
|
+
<Message {...args}>
|
|
39
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
40
|
+
<MessageContent>
|
|
41
|
+
I can help with a variety of tasks: answering questions, providing
|
|
42
|
+
information, assisting with coding, and generating creative content.
|
|
43
|
+
What would you like help with today?
|
|
44
|
+
</MessageContent>
|
|
45
|
+
</Message>
|
|
46
|
+
</div>
|
|
47
|
+
),
|
|
48
|
+
} satisfies Meta<typeof Message>;
|
|
49
|
+
|
|
50
|
+
export default meta;
|
|
51
|
+
type Story = StoryObj<typeof meta>;
|
|
52
|
+
|
|
53
|
+
const IMPORT = `import { Message, MessageAvatar, MessageContent, MessageActions } from '@kitn.ai/ui';`;
|
|
54
|
+
const src = (code: string) => ({
|
|
55
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
/** Interactive playground — an assistant turn; tweak `class` to change layout. */
|
|
59
|
+
export const Playground: Story = {
|
|
60
|
+
...src(`<Message>
|
|
61
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
62
|
+
<MessageContent>I can help with a variety of tasks...</MessageContent>
|
|
63
|
+
</Message>`),
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** A user turn — right-aligned bubble, no avatar. */
|
|
67
|
+
export const UserMessage: Story = {
|
|
68
|
+
render: () => (
|
|
69
|
+
<div class="max-w-2xl">
|
|
70
|
+
<Message class="flex flex-col items-end">
|
|
71
|
+
<MessageContent class="bg-muted text-primary max-w-[85%] rounded-3xl px-5 py-2.5">
|
|
72
|
+
Hello! How can I help you today?
|
|
73
|
+
</MessageContent>
|
|
74
|
+
</Message>
|
|
75
|
+
</div>
|
|
76
|
+
),
|
|
77
|
+
...src(`<Message class="flex flex-col items-end">
|
|
78
|
+
<MessageContent class="bg-muted text-primary max-w-[85%] rounded-3xl px-5 py-2.5">
|
|
79
|
+
Hello! How can I help you today?
|
|
80
|
+
</MessageContent>
|
|
81
|
+
</Message>`),
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/** An assistant turn — avatar plus a secondary-background content block. */
|
|
85
|
+
export const AssistantMessage: Story = {
|
|
86
|
+
render: () => (
|
|
87
|
+
<div class="max-w-2xl">
|
|
88
|
+
<Message>
|
|
89
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
90
|
+
<MessageContent>
|
|
91
|
+
I can help with a variety of tasks: answering questions, providing information,
|
|
92
|
+
assisting with coding, generating creative content. What would you like help with today?
|
|
93
|
+
</MessageContent>
|
|
94
|
+
</Message>
|
|
95
|
+
</div>
|
|
96
|
+
),
|
|
97
|
+
...src(`<Message>
|
|
98
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
99
|
+
<MessageContent>I can help with a variety of tasks...</MessageContent>
|
|
100
|
+
</Message>`),
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/** Assistant turn with a transparent, flush content block (no bubble). */
|
|
104
|
+
export const AssistantNoBg: Story = {
|
|
105
|
+
name: 'Assistant (No Background)',
|
|
106
|
+
render: () => (
|
|
107
|
+
<div class="max-w-2xl">
|
|
108
|
+
<Message>
|
|
109
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
110
|
+
<MessageContent class="bg-transparent p-0">
|
|
111
|
+
I can help with a variety of tasks: answering questions, providing information,
|
|
112
|
+
assisting with coding, generating creative content. What would you like help with today?
|
|
113
|
+
</MessageContent>
|
|
114
|
+
</Message>
|
|
115
|
+
</div>
|
|
116
|
+
),
|
|
117
|
+
...src(`<Message>
|
|
118
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
119
|
+
<MessageContent class="bg-transparent p-0">...</MessageContent>
|
|
120
|
+
</Message>`),
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/** User bubble with hover-revealed edit/copy actions. */
|
|
124
|
+
export const UserAlignedRight: Story = {
|
|
125
|
+
name: 'User (Right-Aligned)',
|
|
126
|
+
render: () => (
|
|
127
|
+
<div class="max-w-2xl">
|
|
128
|
+
<Message class="flex flex-col items-end">
|
|
129
|
+
<div class="group flex flex-col items-end gap-1">
|
|
130
|
+
<MessageContent class="bg-muted text-primary max-w-[85%] rounded-3xl px-5 py-2.5">
|
|
131
|
+
Can you explain how SolidJS reactivity differs from React hooks?
|
|
132
|
+
</MessageContent>
|
|
133
|
+
<MessageActions class="flex gap-0 opacity-0 transition-opacity duration-150 group-hover:opacity-100">
|
|
134
|
+
<Button variant="ghost" size="icon-sm" class="rounded-full" aria-label="Edit message">
|
|
135
|
+
<Pencil class="size-3.5" />
|
|
136
|
+
</Button>
|
|
137
|
+
<Button variant="ghost" size="icon-sm" class="rounded-full" aria-label="Copy message">
|
|
138
|
+
<Copy class="size-3.5" />
|
|
139
|
+
</Button>
|
|
140
|
+
</MessageActions>
|
|
141
|
+
</div>
|
|
142
|
+
</Message>
|
|
143
|
+
</div>
|
|
144
|
+
),
|
|
145
|
+
...src(`<Message class="flex flex-col items-end">
|
|
146
|
+
<div class="group flex flex-col items-end gap-1">
|
|
147
|
+
<MessageContent class="bg-muted text-primary max-w-[85%] rounded-3xl px-5 py-2.5">
|
|
148
|
+
Can you explain how SolidJS reactivity differs from React hooks?
|
|
149
|
+
</MessageContent>
|
|
150
|
+
<MessageActions class="opacity-0 group-hover:opacity-100">
|
|
151
|
+
<Button variant="ghost" size="icon-sm"><Pencil class="size-3.5" /></Button>
|
|
152
|
+
<Button variant="ghost" size="icon-sm"><Copy class="size-3.5" /></Button>
|
|
153
|
+
</MessageActions>
|
|
154
|
+
</div>
|
|
155
|
+
</Message>`),
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/** Markdown body — set `markdown` on `MessageContent` and pass a markdown string. */
|
|
159
|
+
export const MarkdownMessage: Story = {
|
|
160
|
+
render: () => (
|
|
161
|
+
<div class="max-w-2xl">
|
|
162
|
+
<Message>
|
|
163
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
164
|
+
<MessageContent markdown class="bg-transparent p-0">
|
|
165
|
+
{`Here's a **bold** statement with some \`inline code\` and a list:
|
|
166
|
+
|
|
167
|
+
- First item
|
|
168
|
+
- Second item
|
|
169
|
+
- Third item
|
|
170
|
+
|
|
171
|
+
And a code block:
|
|
172
|
+
|
|
173
|
+
\`\`\`typescript
|
|
174
|
+
const greeting = "Hello, world!";
|
|
175
|
+
console.log(greeting);
|
|
176
|
+
\`\`\``}
|
|
177
|
+
</MessageContent>
|
|
178
|
+
</Message>
|
|
179
|
+
</div>
|
|
180
|
+
),
|
|
181
|
+
...src(`<Message>
|
|
182
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
183
|
+
<MessageContent markdown class="bg-transparent p-0">
|
|
184
|
+
{markdownString}
|
|
185
|
+
</MessageContent>
|
|
186
|
+
</Message>`),
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/** Assistant turn with a hover action row (copy / feedback / regenerate). */
|
|
190
|
+
export const WithActions: Story = {
|
|
191
|
+
render: () => (
|
|
192
|
+
<div class="max-w-2xl">
|
|
193
|
+
<Message>
|
|
194
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
195
|
+
<div class="group flex w-full flex-col gap-0">
|
|
196
|
+
<MessageContent class="bg-transparent p-0">
|
|
197
|
+
Here is a response with hover actions below it.
|
|
198
|
+
</MessageContent>
|
|
199
|
+
<MessageActions class="-ml-2.5 flex gap-0 opacity-0 transition-opacity duration-150 group-hover:opacity-100">
|
|
200
|
+
<Button variant="ghost" size="icon-sm" class="rounded-full" aria-label="Copy message">
|
|
201
|
+
<Copy class="size-3.5" />
|
|
202
|
+
</Button>
|
|
203
|
+
<Button variant="ghost" size="icon-sm" class="rounded-full" aria-label="Good response">
|
|
204
|
+
<ThumbsUp class="size-3.5" />
|
|
205
|
+
</Button>
|
|
206
|
+
<Button variant="ghost" size="icon-sm" class="rounded-full" aria-label="Bad response">
|
|
207
|
+
<ThumbsDown class="size-3.5" />
|
|
208
|
+
</Button>
|
|
209
|
+
<Button variant="ghost" size="icon-sm" class="rounded-full" aria-label="Regenerate response">
|
|
210
|
+
<RefreshCw class="size-3.5" />
|
|
211
|
+
</Button>
|
|
212
|
+
</MessageActions>
|
|
213
|
+
</div>
|
|
214
|
+
</Message>
|
|
215
|
+
</div>
|
|
216
|
+
),
|
|
217
|
+
...src(`<Message>
|
|
218
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
219
|
+
<div class="group flex w-full flex-col gap-0">
|
|
220
|
+
<MessageContent class="bg-transparent p-0">Here is a response...</MessageContent>
|
|
221
|
+
<MessageActions class="opacity-0 group-hover:opacity-100">
|
|
222
|
+
<Button variant="ghost" size="icon-sm"><Copy class="size-3.5" /></Button>
|
|
223
|
+
<Button variant="ghost" size="icon-sm"><ThumbsUp class="size-3.5" /></Button>
|
|
224
|
+
<Button variant="ghost" size="icon-sm"><ThumbsDown class="size-3.5" /></Button>
|
|
225
|
+
<Button variant="ghost" size="icon-sm"><RefreshCw class="size-3.5" /></Button>
|
|
226
|
+
</MessageActions>
|
|
227
|
+
</div>
|
|
228
|
+
</Message>`),
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
/** A user + assistant pair showing both layouts together (showcase). */
|
|
232
|
+
export const Conversation: Story = {
|
|
233
|
+
render: () => (
|
|
234
|
+
<div class="max-w-2xl space-y-4">
|
|
235
|
+
<Message class="flex flex-col items-end">
|
|
236
|
+
<MessageContent class="bg-muted text-primary max-w-[85%] rounded-3xl px-5 py-2.5">
|
|
237
|
+
What is TypeScript?
|
|
238
|
+
</MessageContent>
|
|
239
|
+
</Message>
|
|
240
|
+
|
|
241
|
+
<Message>
|
|
242
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
243
|
+
<div class="group flex w-full flex-col gap-0">
|
|
244
|
+
<MessageContent markdown class="bg-transparent p-0">
|
|
245
|
+
{`**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.
|
|
246
|
+
|
|
247
|
+
Key benefits:
|
|
248
|
+
- Catches errors at compile time
|
|
249
|
+
- Better IDE support and autocompletion
|
|
250
|
+
- Makes large codebases more maintainable`}
|
|
251
|
+
</MessageContent>
|
|
252
|
+
<MessageActions class="-ml-2.5 flex gap-0 opacity-0 transition-opacity duration-150 group-hover:opacity-100">
|
|
253
|
+
<Button variant="ghost" size="icon-sm" class="rounded-full" aria-label="Copy message">
|
|
254
|
+
<Copy class="size-3.5" />
|
|
255
|
+
</Button>
|
|
256
|
+
<Button variant="ghost" size="icon-sm" class="rounded-full" aria-label="Good response">
|
|
257
|
+
<ThumbsUp class="size-3.5" />
|
|
258
|
+
</Button>
|
|
259
|
+
<Button variant="ghost" size="icon-sm" class="rounded-full" aria-label="Bad response">
|
|
260
|
+
<ThumbsDown class="size-3.5" />
|
|
261
|
+
</Button>
|
|
262
|
+
<Button variant="ghost" size="icon-sm" class="rounded-full" aria-label="Regenerate response">
|
|
263
|
+
<RefreshCw class="size-3.5" />
|
|
264
|
+
</Button>
|
|
265
|
+
</MessageActions>
|
|
266
|
+
</div>
|
|
267
|
+
</Message>
|
|
268
|
+
</div>
|
|
269
|
+
),
|
|
270
|
+
...src(`<div class="space-y-4">
|
|
271
|
+
<Message class="flex flex-col items-end">
|
|
272
|
+
<MessageContent class="bg-muted text-primary rounded-3xl px-5 py-2.5">
|
|
273
|
+
What is TypeScript?
|
|
274
|
+
</MessageContent>
|
|
275
|
+
</Message>
|
|
276
|
+
<Message>
|
|
277
|
+
<MessageAvatar src="" fallback="AI" alt="Assistant" />
|
|
278
|
+
<MessageContent markdown class="bg-transparent p-0">{answerMarkdown}</MessageContent>
|
|
279
|
+
</Message>
|
|
280
|
+
</div>`),
|
|
281
|
+
};
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { type JSX, For, createSignal, splitProps, Show } from "solid-js";
|
|
2
|
+
import { Tooltip } from "../ui/tooltip";
|
|
3
|
+
import { Copy, Check } from "lucide-solid";
|
|
4
|
+
import { cn } from "../utils/cn";
|
|
5
|
+
import { Markdown } from "./markdown";
|
|
6
|
+
import { Button } from "../ui/button";
|
|
7
|
+
import { actionIcon, BUILTIN_ACTION_LABEL } from "../ui/action-icons";
|
|
8
|
+
import type { ChatMessageAction, CustomAction } from "../elements/chat-types";
|
|
9
|
+
import { useChatConfig, textClass } from "../primitives/chat-config";
|
|
10
|
+
|
|
11
|
+
// --- Message ---
|
|
12
|
+
|
|
13
|
+
export interface MessageProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|
14
|
+
children: JSX.Element;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function Message(props: MessageProps) {
|
|
18
|
+
const [local, rest] = splitProps(props, ["children", "class"]);
|
|
19
|
+
return (
|
|
20
|
+
<div class={cn("flex items-start gap-3", local.class)} {...rest}>
|
|
21
|
+
{local.children}
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// --- MessageAvatar ---
|
|
27
|
+
|
|
28
|
+
export interface MessageAvatarProps {
|
|
29
|
+
src: string;
|
|
30
|
+
alt: string;
|
|
31
|
+
fallback?: string;
|
|
32
|
+
class?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function MessageAvatar(props: MessageAvatarProps) {
|
|
36
|
+
return (
|
|
37
|
+
<div
|
|
38
|
+
class={cn("h-8 w-8 shrink-0 overflow-hidden rounded-full", props.class)}
|
|
39
|
+
>
|
|
40
|
+
<Show
|
|
41
|
+
when={props.src}
|
|
42
|
+
fallback={
|
|
43
|
+
<Show when={props.fallback}>
|
|
44
|
+
<div class="flex h-full w-full items-center justify-center bg-muted text-xs font-medium text-muted-foreground">
|
|
45
|
+
{props.fallback}
|
|
46
|
+
</div>
|
|
47
|
+
</Show>
|
|
48
|
+
}
|
|
49
|
+
>
|
|
50
|
+
<img
|
|
51
|
+
src={props.src}
|
|
52
|
+
alt={props.alt}
|
|
53
|
+
class="h-full w-full object-cover"
|
|
54
|
+
/>
|
|
55
|
+
</Show>
|
|
56
|
+
</div>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// --- MessageContent ---
|
|
61
|
+
|
|
62
|
+
export interface MessageContentProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|
63
|
+
children: JSX.Element | string;
|
|
64
|
+
markdown?: boolean;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function MessageContent(props: MessageContentProps) {
|
|
68
|
+
const [local, rest] = splitProps(props, ["children", "markdown", "class"]);
|
|
69
|
+
const config = useChatConfig();
|
|
70
|
+
const classNames = () =>
|
|
71
|
+
cn(
|
|
72
|
+
"min-w-0 rounded-lg p-2 text-foreground bg-secondary max-w-none break-words whitespace-normal",
|
|
73
|
+
textClass(config.proseSize()),
|
|
74
|
+
local.class,
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<Show
|
|
79
|
+
when={local.markdown}
|
|
80
|
+
fallback={
|
|
81
|
+
<div class={classNames()} {...rest}>
|
|
82
|
+
{local.children}
|
|
83
|
+
</div>
|
|
84
|
+
}
|
|
85
|
+
>
|
|
86
|
+
<Markdown content={local.children as string} class={classNames()} />
|
|
87
|
+
</Show>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// --- MessageActions ---
|
|
92
|
+
|
|
93
|
+
export interface MessageActionsProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|
94
|
+
children: JSX.Element;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function MessageActions(props: MessageActionsProps) {
|
|
98
|
+
const [local, rest] = splitProps(props, ["children", "class"]);
|
|
99
|
+
return (
|
|
100
|
+
<div
|
|
101
|
+
class={cn(
|
|
102
|
+
"flex items-center gap-0.5 mt-0.5",
|
|
103
|
+
local.class,
|
|
104
|
+
)}
|
|
105
|
+
{...rest}
|
|
106
|
+
>
|
|
107
|
+
{local.children}
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// --- MessageActionBar ---
|
|
113
|
+
|
|
114
|
+
export interface MessageActionBarProps {
|
|
115
|
+
/** Built-in action names and/or custom action descriptors, in order. */
|
|
116
|
+
actions: (ChatMessageAction | CustomAction)[];
|
|
117
|
+
/** `'always'` (default) keeps the bar visible; `'hover'` reveals it on
|
|
118
|
+
* parent `.group` hover. */
|
|
119
|
+
reveal?: 'always' | 'hover';
|
|
120
|
+
/** Fired with the built-in name or the custom action id when a button is clicked. */
|
|
121
|
+
onAction: (id: string) => void;
|
|
122
|
+
class?: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Normalize a bar entry (string built-in or custom object) to a uniform shape. */
|
|
126
|
+
function normalizeAction(a: ChatMessageAction | CustomAction) {
|
|
127
|
+
if (typeof a === 'string') {
|
|
128
|
+
return { id: a, label: BUILTIN_ACTION_LABEL[a], Icon: actionIcon(a) };
|
|
129
|
+
}
|
|
130
|
+
return { id: a.id, label: a.label, Icon: actionIcon(a.icon) };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The shared message action toolbar. Renders one ghost icon button per entry —
|
|
135
|
+
* built-in names pull their label+icon from the curated registry; custom
|
|
136
|
+
* descriptors use their `label` plus `actionIcon(icon)` (label-only when the
|
|
137
|
+
* icon is unknown or absent). `reveal="hover"` makes the bar fade in on the
|
|
138
|
+
* parent `.group`'s hover.
|
|
139
|
+
*/
|
|
140
|
+
function MessageActionBar(props: MessageActionBarProps) {
|
|
141
|
+
return (
|
|
142
|
+
<MessageActions
|
|
143
|
+
class={cn(
|
|
144
|
+
'mt-1 flex gap-0',
|
|
145
|
+
props.reveal === 'hover' && 'opacity-0 transition-opacity group-hover:opacity-100',
|
|
146
|
+
props.class,
|
|
147
|
+
)}
|
|
148
|
+
>
|
|
149
|
+
<For each={props.actions}>
|
|
150
|
+
{(a) => {
|
|
151
|
+
const item = normalizeAction(a);
|
|
152
|
+
const tooltipText = () => (typeof a !== 'string' && a.tooltip) ? a.tooltip : item.label;
|
|
153
|
+
// Factory (not a shared node): each Show branch gets its own Button so
|
|
154
|
+
// the eager DOM node is never referenced from two places.
|
|
155
|
+
const button = () => (
|
|
156
|
+
<Button
|
|
157
|
+
variant="ghost"
|
|
158
|
+
size="icon-sm"
|
|
159
|
+
class="rounded-full"
|
|
160
|
+
data-action={item.id}
|
|
161
|
+
aria-label={item.label}
|
|
162
|
+
onClick={() => props.onAction(item.id)}
|
|
163
|
+
>
|
|
164
|
+
<Show when={item.Icon} fallback={<span class="px-1 text-xs">{item.label}</span>}>
|
|
165
|
+
{(Icon) => {
|
|
166
|
+
const I = Icon();
|
|
167
|
+
return <I class="size-3.5" />;
|
|
168
|
+
}}
|
|
169
|
+
</Show>
|
|
170
|
+
</Button>
|
|
171
|
+
);
|
|
172
|
+
// Icon-only buttons get a tooltip; label-only buttons (text already
|
|
173
|
+
// visible) don't.
|
|
174
|
+
return (
|
|
175
|
+
<Show when={item.Icon} fallback={button()}>
|
|
176
|
+
<Tooltip content={tooltipText()}>{button()}</Tooltip>
|
|
177
|
+
</Show>
|
|
178
|
+
);
|
|
179
|
+
}}
|
|
180
|
+
</For>
|
|
181
|
+
</MessageActions>
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// --- MessageAction ---
|
|
186
|
+
|
|
187
|
+
export interface MessageActionProps {
|
|
188
|
+
tooltip: string;
|
|
189
|
+
children: JSX.Element;
|
|
190
|
+
side?: "top" | "bottom" | "left" | "right";
|
|
191
|
+
class?: string;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function MessageAction(props: MessageActionProps) {
|
|
195
|
+
return <>{props.children}</>;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// --- MessageCopyButton ---
|
|
199
|
+
|
|
200
|
+
export interface MessageCopyButtonProps {
|
|
201
|
+
content: string;
|
|
202
|
+
size?: number;
|
|
203
|
+
class?: string;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function MessageCopyButton(props: MessageCopyButtonProps) {
|
|
207
|
+
const [copied, setCopied] = createSignal(false);
|
|
208
|
+
const iconSize = () => props.size ?? 14;
|
|
209
|
+
|
|
210
|
+
return (
|
|
211
|
+
<button
|
|
212
|
+
class={props.class}
|
|
213
|
+
aria-label={copied() ? 'Copied' : 'Copy message'}
|
|
214
|
+
onClick={() => {
|
|
215
|
+
navigator.clipboard.writeText(props.content);
|
|
216
|
+
setCopied(true);
|
|
217
|
+
setTimeout(() => setCopied(false), 2000);
|
|
218
|
+
}}
|
|
219
|
+
>
|
|
220
|
+
<Show when={copied()} fallback={<Copy size={iconSize()} />}>
|
|
221
|
+
<Check size={iconSize()} class="text-emerald-400" />
|
|
222
|
+
</Show>
|
|
223
|
+
</button>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export { Message, MessageAvatar, MessageContent, MessageActions, MessageActionBar, MessageAction, MessageCopyButton };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { fn } from 'storybook/test';
|
|
3
|
+
import { ModelSwitcher } from './model-switcher';
|
|
4
|
+
import { componentDescription } from '../stories/docs/element-controls';
|
|
5
|
+
|
|
6
|
+
const multipleModels = [
|
|
7
|
+
{ id: 'claude-sonnet', name: 'Claude Sonnet', provider: 'Anthropic' },
|
|
8
|
+
{ id: 'claude-opus', name: 'Claude Opus', provider: 'Anthropic' },
|
|
9
|
+
{ id: 'gpt-4o', name: 'GPT-4o', provider: 'OpenAI' },
|
|
10
|
+
{ id: 'gemini-pro', name: 'Gemini Pro', provider: 'Google' },
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
const meta = {
|
|
14
|
+
title: 'Solid (Advanced)/Elements/ModelSwitcher',
|
|
15
|
+
component: ModelSwitcher,
|
|
16
|
+
tags: ['autodocs'],
|
|
17
|
+
parameters: {
|
|
18
|
+
layout: 'padded',
|
|
19
|
+
docs: {
|
|
20
|
+
controls: { exclude: ['use:eventListener'] },
|
|
21
|
+
description: componentDescription([
|
|
22
|
+
'A compact dropdown that shows the active model and lets the user switch between the available **models** (grouped by optional `provider` label).',
|
|
23
|
+
'**When to use:** when a chat surface offers more than one model. It renders nothing when fewer than two models are provided, so it is safe to mount unconditionally.',
|
|
24
|
+
'**How to use:** pass the `models` list and the `currentModelId`, then handle `onModelChange` to update your selected-model state.',
|
|
25
|
+
'**Placement:** the prompt input action bar, a chat header, or a settings/toolbar row near the composer.',
|
|
26
|
+
]),
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
argTypes: {
|
|
30
|
+
models: {
|
|
31
|
+
control: 'object',
|
|
32
|
+
description: 'Selectable models. Each has `id`, `name`, and an optional `provider` label.',
|
|
33
|
+
},
|
|
34
|
+
currentModelId: {
|
|
35
|
+
control: 'text',
|
|
36
|
+
description: 'The `id` of the currently selected model.',
|
|
37
|
+
},
|
|
38
|
+
onModelChange: {
|
|
39
|
+
action: 'modelChange',
|
|
40
|
+
description: 'Fired with the chosen model `id` when the user picks a model.',
|
|
41
|
+
table: { category: 'Events' },
|
|
42
|
+
},
|
|
43
|
+
class: {
|
|
44
|
+
control: 'text',
|
|
45
|
+
description: 'Extra classes applied to the trigger button.',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
args: {
|
|
49
|
+
models: multipleModels,
|
|
50
|
+
currentModelId: 'claude-sonnet',
|
|
51
|
+
onModelChange: fn(),
|
|
52
|
+
},
|
|
53
|
+
render: (args) => <ModelSwitcher {...args} />,
|
|
54
|
+
} satisfies Meta<typeof ModelSwitcher>;
|
|
55
|
+
|
|
56
|
+
export default meta;
|
|
57
|
+
type Story = StoryObj<typeof meta>;
|
|
58
|
+
|
|
59
|
+
const IMPORT = `import { ModelSwitcher } from '@kitn.ai/ui';`;
|
|
60
|
+
const src = (code: string) => ({
|
|
61
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
/** Interactive playground — tweak the controls to explore the switcher. */
|
|
65
|
+
export const Playground: Story = {
|
|
66
|
+
...src(`<ModelSwitcher
|
|
67
|
+
models={models}
|
|
68
|
+
currentModelId={modelId()}
|
|
69
|
+
onModelChange={setModelId}
|
|
70
|
+
/>`),
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/** Several models across providers — the dropdown lists them with provider labels. */
|
|
74
|
+
export const MultipleModels: Story = {
|
|
75
|
+
args: { models: multipleModels, currentModelId: 'claude-sonnet' },
|
|
76
|
+
...src(`<ModelSwitcher
|
|
77
|
+
models={[
|
|
78
|
+
{ id: 'claude-sonnet', name: 'Claude Sonnet', provider: 'Anthropic' },
|
|
79
|
+
{ id: 'gpt-4o', name: 'GPT-4o', provider: 'OpenAI' },
|
|
80
|
+
]}
|
|
81
|
+
currentModelId={modelId()}
|
|
82
|
+
onModelChange={setModelId}
|
|
83
|
+
/>`),
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Rich rows + a collapsible group. `description` renders as the row subtitle
|
|
88
|
+
* (preferred over `provider`), and models sharing a `group` collect under a
|
|
89
|
+
* collapsible section — the ChatGPT-style "Legacy models" pattern.
|
|
90
|
+
*/
|
|
91
|
+
export const GroupedAndDescribed: Story = {
|
|
92
|
+
args: {
|
|
93
|
+
models: [
|
|
94
|
+
{ id: 'gpt-5.5', name: 'GPT-5.5', description: 'Flagship model' },
|
|
95
|
+
{ id: 'gpt-5.5-mini', name: 'GPT-5.5 mini', description: 'Faster, lighter' },
|
|
96
|
+
{ id: 'gpt-4o', name: 'GPT-4o', group: 'Legacy models' },
|
|
97
|
+
{ id: 'gpt-4.1', name: 'GPT-4.1', group: 'Legacy models' },
|
|
98
|
+
],
|
|
99
|
+
currentModelId: 'gpt-5.5',
|
|
100
|
+
},
|
|
101
|
+
...src(`<ModelSwitcher
|
|
102
|
+
models={[
|
|
103
|
+
{ id: 'gpt-5.5', name: 'GPT-5.5', description: 'Flagship model' },
|
|
104
|
+
{ id: 'gpt-4o', name: 'GPT-4o', group: 'Legacy models' },
|
|
105
|
+
{ id: 'gpt-4.1', name: 'GPT-4.1', group: 'Legacy models' },
|
|
106
|
+
]}
|
|
107
|
+
currentModelId={modelId()}
|
|
108
|
+
onModelChange={setModelId}
|
|
109
|
+
/>`),
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/** A single model — the switcher renders nothing (needs 2+ models). */
|
|
113
|
+
export const SingleModel: Story = {
|
|
114
|
+
args: {
|
|
115
|
+
models: [{ id: 'claude-sonnet', name: 'Claude Sonnet' }],
|
|
116
|
+
currentModelId: 'claude-sonnet',
|
|
117
|
+
},
|
|
118
|
+
...src(`<ModelSwitcher
|
|
119
|
+
models={[{ id: 'claude-sonnet', name: 'Claude Sonnet' }]}
|
|
120
|
+
currentModelId="claude-sonnet"
|
|
121
|
+
onModelChange={setModelId}
|
|
122
|
+
/>`),
|
|
123
|
+
};
|