@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,139 @@
|
|
|
1
|
+
import { type JSX, splitProps, children as resolveChildren, For, Show } from 'solid-js';
|
|
2
|
+
import { cn } from '../utils/cn';
|
|
3
|
+
import { Collapsible, CollapsibleTrigger, CollapsibleContent } from '../ui/collapsible';
|
|
4
|
+
import { ChevronDown, Circle } from 'lucide-solid';
|
|
5
|
+
|
|
6
|
+
// --- ChainOfThoughtItem ---
|
|
7
|
+
|
|
8
|
+
export interface ChainOfThoughtItemProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|
9
|
+
children: JSX.Element;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function ChainOfThoughtItem(props: ChainOfThoughtItemProps) {
|
|
13
|
+
const [local, rest] = splitProps(props, ['children', 'class']);
|
|
14
|
+
return (
|
|
15
|
+
<div class={cn('text-muted-foreground text-sm', local.class)} {...rest}>
|
|
16
|
+
{local.children}
|
|
17
|
+
</div>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// --- ChainOfThoughtTrigger ---
|
|
22
|
+
|
|
23
|
+
export interface ChainOfThoughtTriggerProps {
|
|
24
|
+
children: JSX.Element;
|
|
25
|
+
class?: string;
|
|
26
|
+
leftIcon?: JSX.Element;
|
|
27
|
+
swapIconOnHover?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function ChainOfThoughtTrigger(props: ChainOfThoughtTriggerProps) {
|
|
31
|
+
const swapOnHover = () => props.swapIconOnHover ?? true;
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<CollapsibleTrigger
|
|
35
|
+
class={cn(
|
|
36
|
+
'group text-muted-foreground hover:text-foreground flex cursor-pointer items-center justify-start gap-1 text-left text-sm transition-colors',
|
|
37
|
+
props.class
|
|
38
|
+
)}
|
|
39
|
+
>
|
|
40
|
+
<div class="flex items-center gap-2">
|
|
41
|
+
<Show
|
|
42
|
+
when={props.leftIcon}
|
|
43
|
+
fallback={
|
|
44
|
+
<span class="relative inline-flex size-4 items-center justify-center">
|
|
45
|
+
<Circle class="size-2 fill-current" />
|
|
46
|
+
</span>
|
|
47
|
+
}
|
|
48
|
+
>
|
|
49
|
+
<span class="relative inline-flex size-4 items-center justify-center">
|
|
50
|
+
<span
|
|
51
|
+
class={cn(
|
|
52
|
+
'transition-opacity',
|
|
53
|
+
swapOnHover() && 'group-hover:opacity-0'
|
|
54
|
+
)}
|
|
55
|
+
>
|
|
56
|
+
{props.leftIcon}
|
|
57
|
+
</span>
|
|
58
|
+
<Show when={swapOnHover()}>
|
|
59
|
+
<ChevronDown class="absolute size-4 opacity-0 transition-opacity group-hover:opacity-100 group-data-[state=open]:rotate-180" />
|
|
60
|
+
</Show>
|
|
61
|
+
</span>
|
|
62
|
+
</Show>
|
|
63
|
+
<span>{props.children}</span>
|
|
64
|
+
</div>
|
|
65
|
+
<Show when={!props.leftIcon}>
|
|
66
|
+
<ChevronDown class="size-4 transition-transform group-data-[state=open]:rotate-180" />
|
|
67
|
+
</Show>
|
|
68
|
+
</CollapsibleTrigger>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// --- ChainOfThoughtContent ---
|
|
73
|
+
|
|
74
|
+
export interface ChainOfThoughtContentProps {
|
|
75
|
+
children: JSX.Element;
|
|
76
|
+
class?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function ChainOfThoughtContent(props: ChainOfThoughtContentProps) {
|
|
80
|
+
return (
|
|
81
|
+
<CollapsibleContent
|
|
82
|
+
class={cn(
|
|
83
|
+
'text-popover-foreground data-[state=closed]:animate-collapsible-up data-[state=open]:animate-collapsible-down overflow-hidden',
|
|
84
|
+
props.class
|
|
85
|
+
)}
|
|
86
|
+
>
|
|
87
|
+
<div class="grid grid-cols-[min-content_minmax(0,1fr)] gap-x-4">
|
|
88
|
+
<div class="bg-primary/20 ml-1.75 h-full w-px group-data-[last=true]:hidden" />
|
|
89
|
+
<div class="ml-1.75 h-full w-px bg-transparent group-data-[last=false]:hidden" />
|
|
90
|
+
<div class="mt-2 space-y-2">{props.children}</div>
|
|
91
|
+
</div>
|
|
92
|
+
</CollapsibleContent>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// --- ChainOfThought (Root) ---
|
|
97
|
+
|
|
98
|
+
export interface ChainOfThoughtProps {
|
|
99
|
+
children: JSX.Element;
|
|
100
|
+
class?: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function ChainOfThought(props: ChainOfThoughtProps) {
|
|
104
|
+
return (
|
|
105
|
+
<div class={cn('space-y-0', props.class)}>
|
|
106
|
+
{props.children}
|
|
107
|
+
</div>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// --- ChainOfThoughtStep ---
|
|
112
|
+
|
|
113
|
+
export interface ChainOfThoughtStepProps {
|
|
114
|
+
children: JSX.Element;
|
|
115
|
+
class?: string;
|
|
116
|
+
isLast?: boolean;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function ChainOfThoughtStep(props: ChainOfThoughtStepProps) {
|
|
120
|
+
return (
|
|
121
|
+
<Collapsible
|
|
122
|
+
class={cn('group', props.class)}
|
|
123
|
+
data-last={props.isLast ?? false}
|
|
124
|
+
>
|
|
125
|
+
{props.children}
|
|
126
|
+
<div class="flex justify-start group-data-[last=true]:hidden">
|
|
127
|
+
<div class="bg-primary/20 ml-1.75 h-4 w-px" />
|
|
128
|
+
</div>
|
|
129
|
+
</Collapsible>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export {
|
|
134
|
+
ChainOfThought,
|
|
135
|
+
ChainOfThoughtStep,
|
|
136
|
+
ChainOfThoughtTrigger,
|
|
137
|
+
ChainOfThoughtContent,
|
|
138
|
+
ChainOfThoughtItem,
|
|
139
|
+
};
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { For } from 'solid-js';
|
|
3
|
+
import { ChatContainerRoot, ChatContainerContent, ChatContainerScrollAnchor } from './chat-container';
|
|
4
|
+
import { Message, MessageAvatar, MessageContent } from './message';
|
|
5
|
+
|
|
6
|
+
const sampleMessages = [
|
|
7
|
+
{ role: 'user', content: 'What is SolidJS?' },
|
|
8
|
+
{ role: 'assistant', content: '**SolidJS** is a declarative, efficient, and flexible JavaScript library for building user interfaces. Unlike React, it uses fine-grained reactivity with no Virtual DOM, resulting in excellent performance.' },
|
|
9
|
+
{ role: 'user', content: 'How does reactivity work in SolidJS?' },
|
|
10
|
+
{ role: 'assistant', content: `SolidJS uses **signals** as its core reactive primitive. Here's how it works:
|
|
11
|
+
|
|
12
|
+
1. **Signals** -- Store reactive values that track their dependencies
|
|
13
|
+
2. **Effects** -- Side effects that re-run when their signal dependencies change
|
|
14
|
+
3. **Memos** -- Derived values that cache their results
|
|
15
|
+
|
|
16
|
+
Unlike React's useState, SolidJS signals are getter/setter pairs that update only the specific DOM nodes that depend on them.` },
|
|
17
|
+
{ role: 'user', content: 'Can you show me an example?' },
|
|
18
|
+
{ role: 'assistant', content: `Here's a simple counter example:
|
|
19
|
+
|
|
20
|
+
\`\`\`typescript
|
|
21
|
+
import { createSignal } from 'solid-js';
|
|
22
|
+
|
|
23
|
+
function Counter() {
|
|
24
|
+
const [count, setCount] = createSignal(0);
|
|
25
|
+
return (
|
|
26
|
+
<button onClick={() => setCount(c => c + 1)}>
|
|
27
|
+
Count: {count()}
|
|
28
|
+
</button>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
\`\`\`
|
|
32
|
+
|
|
33
|
+
Notice that \`count\` is called as a function -- this is how SolidJS tracks which parts of the UI depend on which signals.` },
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const meta = {
|
|
37
|
+
title: 'Components/ChatContainer',
|
|
38
|
+
component: ChatContainerRoot,
|
|
39
|
+
tags: ['autodocs'],
|
|
40
|
+
parameters: {
|
|
41
|
+
layout: 'padded',
|
|
42
|
+
docs: {
|
|
43
|
+
description: {
|
|
44
|
+
component: [
|
|
45
|
+
'A scrollable message viewport that automatically sticks to the bottom as new content streams in. Composed of `ChatContainerRoot` (the scroll region), `ChatContainerContent` (the message stack), and `ChatContainerScrollAnchor` (the stick-to-bottom target).',
|
|
46
|
+
'**When to use:** as the conversation transcript region of a chat UI, where messages append over time and the view should follow the latest output unless the user scrolls up.',
|
|
47
|
+
'**How to use:** wrap your message list in `ChatContainerRoot`, place messages inside `ChatContainerContent`, and end with `ChatContainerScrollAnchor`. Give the root a fixed height so it can scroll.',
|
|
48
|
+
'**Placement:** the central pane of a chat layout, between the header and the prompt input.',
|
|
49
|
+
].join('\n\n'),
|
|
50
|
+
},
|
|
51
|
+
controls: { exclude: ['use:eventListener'] },
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
argTypes: {
|
|
55
|
+
children: {
|
|
56
|
+
control: false,
|
|
57
|
+
description: 'The container content — typically `ChatContainerContent` with messages.',
|
|
58
|
+
},
|
|
59
|
+
class: {
|
|
60
|
+
control: 'text',
|
|
61
|
+
description: 'Extra classes for the scroll region (set a height so it can scroll).',
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
args: {
|
|
65
|
+
class: 'h-full flex-col p-4',
|
|
66
|
+
},
|
|
67
|
+
render: (args) => (
|
|
68
|
+
<div class="h-[500px] w-full max-w-2xl border border-border rounded-lg overflow-hidden">
|
|
69
|
+
<ChatContainerRoot {...args}>
|
|
70
|
+
<ChatContainerContent class="space-y-4">
|
|
71
|
+
<For each={sampleMessages}>
|
|
72
|
+
{(msg) => (
|
|
73
|
+
<Message>
|
|
74
|
+
<MessageAvatar src="" fallback={msg.role === 'user' ? 'U' : 'AI'} alt={msg.role} />
|
|
75
|
+
<MessageContent markdown={msg.role === 'assistant'}>{msg.content}</MessageContent>
|
|
76
|
+
</Message>
|
|
77
|
+
)}
|
|
78
|
+
</For>
|
|
79
|
+
<ChatContainerScrollAnchor />
|
|
80
|
+
</ChatContainerContent>
|
|
81
|
+
</ChatContainerRoot>
|
|
82
|
+
</div>
|
|
83
|
+
),
|
|
84
|
+
} satisfies Meta<typeof ChatContainerRoot>;
|
|
85
|
+
|
|
86
|
+
export default meta;
|
|
87
|
+
type Story = StoryObj<typeof meta>;
|
|
88
|
+
|
|
89
|
+
const IMPORT = `import {
|
|
90
|
+
ChatContainerRoot, ChatContainerContent, ChatContainerScrollAnchor,
|
|
91
|
+
Message, MessageAvatar, MessageContent,
|
|
92
|
+
} from '@kitnai/chat';`;
|
|
93
|
+
const src = (code: string) => ({
|
|
94
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
/** Interactive playground — a full transcript inside the stick-to-bottom container. */
|
|
98
|
+
export const Playground: Story = {
|
|
99
|
+
...src(`<div class="h-[500px]">
|
|
100
|
+
<ChatContainerRoot class="h-full flex-col p-4">
|
|
101
|
+
<ChatContainerContent class="space-y-4">
|
|
102
|
+
<For each={messages}>
|
|
103
|
+
{(msg) => (
|
|
104
|
+
<Message>
|
|
105
|
+
<MessageAvatar src="" fallback={msg.role === 'user' ? 'U' : 'AI'} alt={msg.role} />
|
|
106
|
+
<MessageContent markdown={msg.role === 'assistant'}>{msg.content}</MessageContent>
|
|
107
|
+
</Message>
|
|
108
|
+
)}
|
|
109
|
+
</For>
|
|
110
|
+
<ChatContainerScrollAnchor />
|
|
111
|
+
</ChatContainerContent>
|
|
112
|
+
</ChatContainerRoot>
|
|
113
|
+
</div>`),
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export const FullChat: Story = {
|
|
117
|
+
render: () => (
|
|
118
|
+
<div class="h-[500px] w-full max-w-2xl border border-border rounded-lg overflow-hidden">
|
|
119
|
+
<ChatContainerRoot class="h-full flex-col p-4">
|
|
120
|
+
<ChatContainerContent class="space-y-4">
|
|
121
|
+
<For each={sampleMessages}>
|
|
122
|
+
{(msg) => (
|
|
123
|
+
<Message>
|
|
124
|
+
<MessageAvatar src="" fallback={msg.role === 'user' ? 'U' : 'AI'} alt={msg.role} />
|
|
125
|
+
<MessageContent markdown={msg.role === 'assistant'}>{msg.content}</MessageContent>
|
|
126
|
+
</Message>
|
|
127
|
+
)}
|
|
128
|
+
</For>
|
|
129
|
+
<ChatContainerScrollAnchor />
|
|
130
|
+
</ChatContainerContent>
|
|
131
|
+
</ChatContainerRoot>
|
|
132
|
+
</div>
|
|
133
|
+
),
|
|
134
|
+
...src(`<ChatContainerRoot class="h-full flex-col p-4">
|
|
135
|
+
<ChatContainerContent class="space-y-4">
|
|
136
|
+
<For each={messages}>
|
|
137
|
+
{(msg) => (
|
|
138
|
+
<Message>
|
|
139
|
+
<MessageAvatar src="" fallback={msg.role === 'user' ? 'U' : 'AI'} alt={msg.role} />
|
|
140
|
+
<MessageContent markdown={msg.role === 'assistant'}>{msg.content}</MessageContent>
|
|
141
|
+
</Message>
|
|
142
|
+
)}
|
|
143
|
+
</For>
|
|
144
|
+
<ChatContainerScrollAnchor />
|
|
145
|
+
</ChatContainerContent>
|
|
146
|
+
</ChatContainerRoot>`),
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export const LongConversation: Story = {
|
|
150
|
+
render: () => {
|
|
151
|
+
const manyMessages = Array.from({ length: 20 }, (_, i) => ({
|
|
152
|
+
role: i % 2 === 0 ? 'user' : 'assistant',
|
|
153
|
+
content: i % 2 === 0
|
|
154
|
+
? `This is user message number ${Math.floor(i / 2) + 1}. It asks a question about the topic.`
|
|
155
|
+
: `This is the assistant's response to message ${Math.floor(i / 2) + 1}. It provides a detailed explanation with relevant examples and context.`,
|
|
156
|
+
}));
|
|
157
|
+
return (
|
|
158
|
+
<div class="h-[400px] w-full max-w-2xl border border-border rounded-lg overflow-hidden">
|
|
159
|
+
<ChatContainerRoot class="h-full flex-col p-4">
|
|
160
|
+
<ChatContainerContent class="space-y-4">
|
|
161
|
+
<For each={manyMessages}>
|
|
162
|
+
{(msg) => (
|
|
163
|
+
<Message>
|
|
164
|
+
<MessageAvatar src="" fallback={msg.role === 'user' ? 'U' : 'AI'} alt={msg.role} />
|
|
165
|
+
<MessageContent>{msg.content}</MessageContent>
|
|
166
|
+
</Message>
|
|
167
|
+
)}
|
|
168
|
+
</For>
|
|
169
|
+
<ChatContainerScrollAnchor />
|
|
170
|
+
</ChatContainerContent>
|
|
171
|
+
</ChatContainerRoot>
|
|
172
|
+
</div>
|
|
173
|
+
);
|
|
174
|
+
},
|
|
175
|
+
...src(`<ChatContainerRoot class="h-full flex-col p-4">
|
|
176
|
+
<ChatContainerContent class="space-y-4">
|
|
177
|
+
<For each={manyMessages}>
|
|
178
|
+
{(msg) => (
|
|
179
|
+
<Message>
|
|
180
|
+
<MessageAvatar src="" fallback={msg.role === 'user' ? 'U' : 'AI'} alt={msg.role} />
|
|
181
|
+
<MessageContent>{msg.content}</MessageContent>
|
|
182
|
+
</Message>
|
|
183
|
+
)}
|
|
184
|
+
</For>
|
|
185
|
+
<ChatContainerScrollAnchor />
|
|
186
|
+
</ChatContainerContent>
|
|
187
|
+
</ChatContainerRoot>`),
|
|
188
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type JSX, splitProps, createContext, useContext } from 'solid-js';
|
|
2
|
+
import { cn } from '../utils/cn';
|
|
3
|
+
import { useStickToBottom } from '../primitives/use-stick-to-bottom';
|
|
4
|
+
|
|
5
|
+
interface ChatContainerContextValue {
|
|
6
|
+
isAtBottom: () => boolean;
|
|
7
|
+
scrollToBottom: (behavior?: ScrollBehavior) => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const ChatContainerContext = createContext<ChatContainerContextValue>();
|
|
11
|
+
|
|
12
|
+
export function useChatContainer() {
|
|
13
|
+
const ctx = useContext(ChatContainerContext);
|
|
14
|
+
if (!ctx) throw new Error('useChatContainer must be used within ChatContainer');
|
|
15
|
+
return ctx;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// --- ChatContainerRoot ---
|
|
19
|
+
|
|
20
|
+
export interface ChatContainerRootProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|
21
|
+
children: JSX.Element;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function ChatContainerRoot(props: ChatContainerRootProps) {
|
|
25
|
+
const [local, rest] = splitProps(props, ['children', 'class']);
|
|
26
|
+
const { ref, isAtBottom, scrollToBottom } = useStickToBottom();
|
|
27
|
+
return (
|
|
28
|
+
<ChatContainerContext.Provider value={{ isAtBottom, scrollToBottom }}>
|
|
29
|
+
<div
|
|
30
|
+
ref={ref}
|
|
31
|
+
class={cn('flex flex-col overflow-y-auto', local.class)}
|
|
32
|
+
role="log"
|
|
33
|
+
{...rest}
|
|
34
|
+
>
|
|
35
|
+
{local.children}
|
|
36
|
+
</div>
|
|
37
|
+
</ChatContainerContext.Provider>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// --- ChatContainerContent ---
|
|
42
|
+
|
|
43
|
+
export interface ChatContainerContentProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|
44
|
+
children: JSX.Element;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function ChatContainerContent(props: ChatContainerContentProps) {
|
|
48
|
+
const [local, rest] = splitProps(props, ['children', 'class']);
|
|
49
|
+
return (
|
|
50
|
+
<div class={cn('flex w-full flex-col', local.class)} {...rest}>
|
|
51
|
+
{local.children}
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// --- ChatContainerScrollAnchor ---
|
|
57
|
+
|
|
58
|
+
export interface ChatContainerScrollAnchorProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|
59
|
+
ref?: HTMLDivElement | ((el: HTMLDivElement) => void);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function ChatContainerScrollAnchor(props: ChatContainerScrollAnchorProps) {
|
|
63
|
+
const [local, rest] = splitProps(props, ['class']);
|
|
64
|
+
return (
|
|
65
|
+
<div
|
|
66
|
+
class={cn('h-px w-full shrink-0 scroll-mt-4', local.class)}
|
|
67
|
+
aria-hidden="true"
|
|
68
|
+
{...rest}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
ChatContainerRoot as ChatContainer,
|
|
75
|
+
ChatContainerRoot,
|
|
76
|
+
ChatContainerContent,
|
|
77
|
+
ChatContainerScrollAnchor,
|
|
78
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { splitProps, Show, For } from 'solid-js';
|
|
2
|
+
import { cn } from '../utils/cn';
|
|
3
|
+
import { Dropdown, DropdownTrigger, DropdownContent, DropdownItem } from '../ui/dropdown';
|
|
4
|
+
import { Button } from '../ui/button';
|
|
5
|
+
import type { SearchFilters } from '../types';
|
|
6
|
+
|
|
7
|
+
export interface ChatScopePickerProps {
|
|
8
|
+
currentLabel: string;
|
|
9
|
+
onScopeChange: (filters: SearchFilters | undefined) => void;
|
|
10
|
+
availableAuthors?: string[];
|
|
11
|
+
availableTags?: string[];
|
|
12
|
+
class?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function ChatScopePicker(props: ChatScopePickerProps) {
|
|
16
|
+
const [local] = splitProps(props, ['currentLabel', 'onScopeChange', 'availableAuthors', 'availableTags', 'class']);
|
|
17
|
+
return (
|
|
18
|
+
<Dropdown>
|
|
19
|
+
<DropdownTrigger as={(triggerProps: any) => (
|
|
20
|
+
<Button variant="ghost" size="sm" class={cn('gap-1 text-xs', local.class)} {...triggerProps}>
|
|
21
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"/></svg>
|
|
22
|
+
{local.currentLabel}
|
|
23
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg>
|
|
24
|
+
</Button>
|
|
25
|
+
)} />
|
|
26
|
+
<DropdownContent class="min-w-[180px]">
|
|
27
|
+
<DropdownItem onSelect={() => local.onScopeChange(undefined)}>All Content</DropdownItem>
|
|
28
|
+
<Show when={local.availableAuthors?.length}>
|
|
29
|
+
<div class="px-2 py-1 text-[10px] uppercase tracking-wider text-muted-foreground/60">Authors</div>
|
|
30
|
+
<For each={local.availableAuthors}>
|
|
31
|
+
{(author) => (
|
|
32
|
+
<DropdownItem onSelect={() => local.onScopeChange({ authors: [author] })}>{author}</DropdownItem>
|
|
33
|
+
)}
|
|
34
|
+
</For>
|
|
35
|
+
</Show>
|
|
36
|
+
<Show when={local.availableTags?.length}>
|
|
37
|
+
<div class="px-2 py-1 text-[10px] uppercase tracking-wider text-muted-foreground/60">Tags</div>
|
|
38
|
+
<For each={local.availableTags}>
|
|
39
|
+
{(tag) => (
|
|
40
|
+
<DropdownItem onSelect={() => local.onScopeChange({ tags: [tag] })}>{tag}</DropdownItem>
|
|
41
|
+
)}
|
|
42
|
+
</For>
|
|
43
|
+
</Show>
|
|
44
|
+
</DropdownContent>
|
|
45
|
+
</Dropdown>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { fn } from 'storybook/test';
|
|
3
|
+
import { Checkpoint, CheckpointIcon, CheckpointTrigger } from './checkpoint';
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'Components/Checkpoint',
|
|
7
|
+
component: Checkpoint,
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
parameters: {
|
|
10
|
+
layout: 'padded',
|
|
11
|
+
docs: {
|
|
12
|
+
description: {
|
|
13
|
+
component: [
|
|
14
|
+
'An inline marker that lets a user restore the conversation to a saved point. Composed of `Checkpoint` (row + separator) wrapping a `CheckpointIcon` and a `CheckpointTrigger` button.',
|
|
15
|
+
'**When to use:** to mark a restorable state in a transcript — e.g. before an edit or a branching action — so the user can revert to it.',
|
|
16
|
+
'**How to use:** place a `CheckpointIcon` and a `CheckpointTrigger` inside `Checkpoint`. Give the trigger an `onClick` handler and an optional `tooltip`; pass custom SVG children to `CheckpointIcon` to override the default flag.',
|
|
17
|
+
'**Placement:** between messages in a chat transcript, as a thin separator-style row.',
|
|
18
|
+
].join('\n\n'),
|
|
19
|
+
},
|
|
20
|
+
controls: { exclude: ['use:eventListener'] },
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
argTypes: {
|
|
24
|
+
children: {
|
|
25
|
+
control: false,
|
|
26
|
+
description: 'The `CheckpointIcon` and `CheckpointTrigger` contents.',
|
|
27
|
+
},
|
|
28
|
+
class: {
|
|
29
|
+
control: 'text',
|
|
30
|
+
description: 'Extra classes for the checkpoint row.',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
args: {},
|
|
34
|
+
render: (args) => (
|
|
35
|
+
<div class="max-w-md">
|
|
36
|
+
<Checkpoint {...args}>
|
|
37
|
+
<CheckpointIcon />
|
|
38
|
+
<CheckpointTrigger tooltip="Restore to this point" onClick={fn()}>
|
|
39
|
+
Restore
|
|
40
|
+
</CheckpointTrigger>
|
|
41
|
+
</Checkpoint>
|
|
42
|
+
</div>
|
|
43
|
+
),
|
|
44
|
+
} satisfies Meta<typeof Checkpoint>;
|
|
45
|
+
|
|
46
|
+
export default meta;
|
|
47
|
+
type Story = StoryObj<typeof meta>;
|
|
48
|
+
|
|
49
|
+
const IMPORT = `import { Checkpoint, CheckpointIcon, CheckpointTrigger } from '@kitnai/chat';`;
|
|
50
|
+
const src = (code: string) => ({
|
|
51
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
/** Interactive playground — the default flag icon with a restore trigger. */
|
|
55
|
+
export const Playground: Story = {
|
|
56
|
+
...src(`<Checkpoint>
|
|
57
|
+
<CheckpointIcon />
|
|
58
|
+
<CheckpointTrigger tooltip="Restore to this point" onClick={handleRestore}>
|
|
59
|
+
Restore
|
|
60
|
+
</CheckpointTrigger>
|
|
61
|
+
</Checkpoint>`),
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const WithCustomIcon: Story = {
|
|
65
|
+
render: () => (
|
|
66
|
+
<div class="max-w-md">
|
|
67
|
+
<Checkpoint>
|
|
68
|
+
<CheckpointIcon>
|
|
69
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="size-4">
|
|
70
|
+
<path d="M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10z" />
|
|
71
|
+
<path d="M12 6v6l4 2" />
|
|
72
|
+
</svg>
|
|
73
|
+
</CheckpointIcon>
|
|
74
|
+
<CheckpointTrigger tooltip="Go back to this checkpoint" onClick={fn()}>
|
|
75
|
+
Revert to checkpoint
|
|
76
|
+
</CheckpointTrigger>
|
|
77
|
+
</Checkpoint>
|
|
78
|
+
</div>
|
|
79
|
+
),
|
|
80
|
+
...src(`<Checkpoint>
|
|
81
|
+
<CheckpointIcon>
|
|
82
|
+
<ClockIcon class="size-4" />
|
|
83
|
+
</CheckpointIcon>
|
|
84
|
+
<CheckpointTrigger tooltip="Go back to this checkpoint" onClick={handleRevert}>
|
|
85
|
+
Revert to checkpoint
|
|
86
|
+
</CheckpointTrigger>
|
|
87
|
+
</Checkpoint>`),
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const NoTooltip: Story = {
|
|
91
|
+
render: () => (
|
|
92
|
+
<div class="max-w-md">
|
|
93
|
+
<Checkpoint>
|
|
94
|
+
<CheckpointIcon />
|
|
95
|
+
<CheckpointTrigger onClick={fn()}>Restore</CheckpointTrigger>
|
|
96
|
+
</Checkpoint>
|
|
97
|
+
</div>
|
|
98
|
+
),
|
|
99
|
+
...src(`<Checkpoint>
|
|
100
|
+
<CheckpointIcon />
|
|
101
|
+
<CheckpointTrigger onClick={handleRestore}>Restore</CheckpointTrigger>
|
|
102
|
+
</Checkpoint>`),
|
|
103
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type JSX, Show, splitProps } from 'solid-js';
|
|
2
|
+
import { cn } from '../utils/cn';
|
|
3
|
+
import { Button } from '../ui/button';
|
|
4
|
+
import { Tooltip } from '../ui/tooltip';
|
|
5
|
+
import { Separator } from '../ui/separator';
|
|
6
|
+
|
|
7
|
+
export interface CheckpointProps extends JSX.HTMLAttributes<HTMLDivElement> {}
|
|
8
|
+
|
|
9
|
+
export function Checkpoint(props: CheckpointProps) {
|
|
10
|
+
const [local, rest] = splitProps(props, ['class', 'children']);
|
|
11
|
+
return (
|
|
12
|
+
<div
|
|
13
|
+
class={cn(
|
|
14
|
+
'flex items-center gap-0.5 overflow-hidden text-muted-foreground',
|
|
15
|
+
local.class
|
|
16
|
+
)}
|
|
17
|
+
{...rest}
|
|
18
|
+
>
|
|
19
|
+
{local.children}
|
|
20
|
+
<Separator />
|
|
21
|
+
</div>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface CheckpointIconProps {
|
|
26
|
+
class?: string;
|
|
27
|
+
children?: JSX.Element;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function CheckpointIcon(props: CheckpointIconProps) {
|
|
31
|
+
return (
|
|
32
|
+
<Show
|
|
33
|
+
when={!props.children}
|
|
34
|
+
fallback={props.children}
|
|
35
|
+
>
|
|
36
|
+
<svg
|
|
37
|
+
width="16"
|
|
38
|
+
height="16"
|
|
39
|
+
viewBox="0 0 24 24"
|
|
40
|
+
fill="none"
|
|
41
|
+
stroke="currentColor"
|
|
42
|
+
stroke-width="2"
|
|
43
|
+
class={cn('size-4 shrink-0', props.class)}
|
|
44
|
+
>
|
|
45
|
+
<path d="M19 21l-7-5-7 5V5a2 2 0 012-2h10a2 2 0 012 2z" />
|
|
46
|
+
</svg>
|
|
47
|
+
</Show>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface CheckpointTriggerProps {
|
|
52
|
+
tooltip?: string;
|
|
53
|
+
onClick?: () => void;
|
|
54
|
+
children?: JSX.Element;
|
|
55
|
+
class?: string;
|
|
56
|
+
variant?: 'ghost' | 'default' | 'outline';
|
|
57
|
+
size?: 'sm' | 'md' | 'lg' | 'icon' | 'icon-sm';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function CheckpointTrigger(props: CheckpointTriggerProps) {
|
|
61
|
+
const variant = () => props.variant ?? 'ghost';
|
|
62
|
+
const size = () => props.size ?? 'sm';
|
|
63
|
+
|
|
64
|
+
const button = (
|
|
65
|
+
<Button
|
|
66
|
+
variant={variant()}
|
|
67
|
+
size={size()}
|
|
68
|
+
type="button"
|
|
69
|
+
onClick={props.onClick}
|
|
70
|
+
class={props.class}
|
|
71
|
+
>
|
|
72
|
+
{props.children}
|
|
73
|
+
</Button>
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<Show when={props.tooltip} fallback={button}>
|
|
78
|
+
<Tooltip content={props.tooltip!}>{button}</Tooltip>
|
|
79
|
+
</Show>
|
|
80
|
+
);
|
|
81
|
+
}
|