@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,88 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { TextShimmer } from './text-shimmer';
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
title: 'Components/TextShimmer',
|
|
6
|
+
component: TextShimmer,
|
|
7
|
+
tags: ['autodocs'],
|
|
8
|
+
parameters: {
|
|
9
|
+
layout: 'padded',
|
|
10
|
+
docs: {
|
|
11
|
+
controls: { exclude: ['use:eventListener'] },
|
|
12
|
+
description: {
|
|
13
|
+
component: [
|
|
14
|
+
'An animated text effect that sweeps a light gradient across its content, rendered into any element tag via `as`.',
|
|
15
|
+
'**When to use:** to signal an in-progress / loading state with a label — e.g. "Thinking", "Generating", "Searching" — or to draw subtle attention to a transient status line.',
|
|
16
|
+
'**How to use:** wrap text in `<TextShimmer>`; tune `duration` (seconds per sweep) and `spread` (gradient width, clamped 5–45). Use `as` to change the wrapping tag (e.g. `"h2"`) and pass any standard HTML attributes.',
|
|
17
|
+
'**Placement:** loading indicators, streaming status lines, thinking bars, and placeholder labels.',
|
|
18
|
+
].join('\n\n'),
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
argTypes: {
|
|
23
|
+
as: {
|
|
24
|
+
control: 'text',
|
|
25
|
+
description: 'HTML tag to render the shimmer into.',
|
|
26
|
+
table: { defaultValue: { summary: 'span' } },
|
|
27
|
+
},
|
|
28
|
+
duration: {
|
|
29
|
+
control: 'number',
|
|
30
|
+
description: 'Seconds for one full shimmer sweep.',
|
|
31
|
+
table: { defaultValue: { summary: '4' } },
|
|
32
|
+
},
|
|
33
|
+
spread: {
|
|
34
|
+
control: 'number',
|
|
35
|
+
description: 'Width of the gradient highlight (clamped to 5–45).',
|
|
36
|
+
table: { defaultValue: { summary: '20' } },
|
|
37
|
+
},
|
|
38
|
+
children: {
|
|
39
|
+
control: 'text',
|
|
40
|
+
description: 'Text to apply the shimmer effect to.',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
args: {
|
|
44
|
+
as: 'span',
|
|
45
|
+
duration: 4,
|
|
46
|
+
spread: 20,
|
|
47
|
+
children: 'Shimmering text effect',
|
|
48
|
+
},
|
|
49
|
+
render: (args) => <TextShimmer {...args} />,
|
|
50
|
+
} satisfies Meta<typeof TextShimmer>;
|
|
51
|
+
|
|
52
|
+
export default meta;
|
|
53
|
+
type Story = StoryObj<typeof meta>;
|
|
54
|
+
|
|
55
|
+
const IMPORT = `import { TextShimmer } from '@kitnai/chat';`;
|
|
56
|
+
const src = (code: string) => ({
|
|
57
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
/** Interactive playground — tweak the controls to explore the shimmer effect. */
|
|
61
|
+
export const Playground: Story = {
|
|
62
|
+
...src(`<TextShimmer duration={4} spread={20}>Shimmering text effect</TextShimmer>`),
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const FastShimmer: Story = {
|
|
66
|
+
args: { duration: 1.5, children: 'Fast shimmer animation' },
|
|
67
|
+
...src(`<TextShimmer duration={1.5}>Fast shimmer animation</TextShimmer>`),
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const SlowShimmer: Story = {
|
|
71
|
+
args: { duration: 8, children: 'Slow shimmer animation' },
|
|
72
|
+
...src(`<TextShimmer duration={8}>Slow shimmer animation</TextShimmer>`),
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const WideSpread: Story = {
|
|
76
|
+
args: { spread: 40, children: 'Wide spread shimmer' },
|
|
77
|
+
...src(`<TextShimmer spread={40}>Wide spread shimmer</TextShimmer>`),
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const NarrowSpread: Story = {
|
|
81
|
+
args: { spread: 5, children: 'Narrow spread shimmer' },
|
|
82
|
+
...src(`<TextShimmer spread={5}>Narrow spread shimmer</TextShimmer>`),
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const AsHeading: Story = {
|
|
86
|
+
args: { as: 'h2', class: 'text-2xl', children: 'Shimmer Heading' } as never,
|
|
87
|
+
...src(`<TextShimmer as="h2" class="text-2xl">Shimmer Heading</TextShimmer>`),
|
|
88
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type JSX, splitProps } from 'solid-js';
|
|
2
|
+
import { cn } from '../utils/cn';
|
|
3
|
+
import { Dynamic } from 'solid-js/web';
|
|
4
|
+
|
|
5
|
+
export interface TextShimmerProps extends JSX.HTMLAttributes<HTMLElement> {
|
|
6
|
+
as?: string;
|
|
7
|
+
duration?: number;
|
|
8
|
+
spread?: number;
|
|
9
|
+
children: JSX.Element;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function TextShimmer(props: TextShimmerProps) {
|
|
13
|
+
const [local, rest] = splitProps(props, ['as', 'class', 'duration', 'spread', 'children']);
|
|
14
|
+
|
|
15
|
+
const dynamicSpread = () => Math.min(Math.max(local.spread ?? 20, 5), 45);
|
|
16
|
+
const tag = () => local.as ?? 'span';
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Dynamic
|
|
20
|
+
component={tag()}
|
|
21
|
+
class={cn(
|
|
22
|
+
'bg-size-[200%_auto] bg-clip-text font-medium text-transparent',
|
|
23
|
+
'animate-[shimmer_4s_infinite_linear]',
|
|
24
|
+
local.class
|
|
25
|
+
)}
|
|
26
|
+
style={{
|
|
27
|
+
'background-image': `linear-gradient(to right, var(--color-muted-foreground) ${50 - dynamicSpread()}%, var(--color-foreground) 50%, var(--color-muted-foreground) ${50 + dynamicSpread()}%)`,
|
|
28
|
+
'animation-duration': `${local.duration ?? 4}s`,
|
|
29
|
+
}}
|
|
30
|
+
{...rest}
|
|
31
|
+
>
|
|
32
|
+
{local.children}
|
|
33
|
+
</Dynamic>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { TextShimmer };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { fn } from 'storybook/test';
|
|
3
|
+
import { ThinkingBar } from './thinking-bar';
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'Components/ThinkingBar',
|
|
7
|
+
component: ThinkingBar,
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
parameters: {
|
|
10
|
+
layout: 'padded',
|
|
11
|
+
docs: {
|
|
12
|
+
controls: { exclude: ['use:eventListener'] },
|
|
13
|
+
description: {
|
|
14
|
+
component: [
|
|
15
|
+
'A status row that shows a shimmering "thinking" label, optionally clickable to expand reasoning, with an optional stop/cancel action.',
|
|
16
|
+
'**When to use:** while the assistant is generating or reasoning, to show live activity and give the user a way to interrupt or to open the reasoning trace.',
|
|
17
|
+
'**How to use:** set `text` for the label. Pass `onClick` to make the label a button (adds a chevron) — typically to toggle a reasoning panel. Pass `onStop` (with optional `stopLabel`) to render the interrupt action.',
|
|
18
|
+
'**Placement:** above or in place of a streaming message, or at the top of a reasoning/chain-of-thought block.',
|
|
19
|
+
].join('\n\n'),
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
argTypes: {
|
|
24
|
+
text: {
|
|
25
|
+
control: 'text',
|
|
26
|
+
description: 'Label shown with the shimmer effect.',
|
|
27
|
+
table: { defaultValue: { summary: 'Thinking' } },
|
|
28
|
+
},
|
|
29
|
+
stopLabel: {
|
|
30
|
+
control: 'text',
|
|
31
|
+
description: 'Label for the stop/cancel action (only shown when `onStop` is set).',
|
|
32
|
+
table: { defaultValue: { summary: 'Answer now' } },
|
|
33
|
+
},
|
|
34
|
+
class: {
|
|
35
|
+
control: 'text',
|
|
36
|
+
description: 'Additional CSS classes for the container.',
|
|
37
|
+
},
|
|
38
|
+
onClick: {
|
|
39
|
+
action: 'click',
|
|
40
|
+
description: 'When set, the label becomes a button (with chevron) and this fires on click.',
|
|
41
|
+
table: { category: 'Events' },
|
|
42
|
+
},
|
|
43
|
+
onStop: {
|
|
44
|
+
action: 'stop',
|
|
45
|
+
description: 'When set, renders the stop action and fires when it is clicked.',
|
|
46
|
+
table: { category: 'Events' },
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
args: {
|
|
50
|
+
text: 'Thinking',
|
|
51
|
+
stopLabel: 'Answer now',
|
|
52
|
+
onStop: fn(),
|
|
53
|
+
},
|
|
54
|
+
render: (args) => <ThinkingBar {...args} />,
|
|
55
|
+
} satisfies Meta<typeof ThinkingBar>;
|
|
56
|
+
|
|
57
|
+
export default meta;
|
|
58
|
+
type Story = StoryObj<typeof meta>;
|
|
59
|
+
|
|
60
|
+
const IMPORT = `import { ThinkingBar } from '@kitnai/chat';`;
|
|
61
|
+
const src = (code: string) => ({
|
|
62
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
/** Interactive playground — tweak the controls to explore the thinking bar. */
|
|
66
|
+
export const Playground: Story = {
|
|
67
|
+
...src(`<ThinkingBar text="Thinking" onStop={() => stop()} />`),
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const Default: Story = {
|
|
71
|
+
args: { onStop: undefined } as never,
|
|
72
|
+
...src(`<ThinkingBar />`),
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const WithStopButton: Story = {
|
|
76
|
+
args: { onStop: fn() },
|
|
77
|
+
...src(`<ThinkingBar onStop={() => stopGeneration()} />`),
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const CustomText: Story = {
|
|
81
|
+
args: { text: 'Analyzing documents', stopLabel: 'Cancel', onStop: fn() },
|
|
82
|
+
...src(`<ThinkingBar text="Analyzing documents" stopLabel="Cancel" onStop={() => cancel()} />`),
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const Clickable: Story = {
|
|
86
|
+
args: { text: 'Reasoning', onClick: fn(), onStop: fn() },
|
|
87
|
+
...src(`<ThinkingBar\n text="Reasoning"\n onClick={() => toggleReasoning()}\n onStop={() => stop()}\n/>`),
|
|
88
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type JSX, splitProps, Show } from 'solid-js';
|
|
2
|
+
import { cn } from '../utils/cn';
|
|
3
|
+
import { TextShimmer } from './text-shimmer';
|
|
4
|
+
import { ChevronRight } from 'lucide-solid';
|
|
5
|
+
|
|
6
|
+
export interface ThinkingBarProps {
|
|
7
|
+
class?: string;
|
|
8
|
+
text?: string;
|
|
9
|
+
onStop?: () => void;
|
|
10
|
+
stopLabel?: string;
|
|
11
|
+
onClick?: () => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function ThinkingBar(props: ThinkingBarProps) {
|
|
15
|
+
const [local] = splitProps(props, ['class', 'text', 'onStop', 'stopLabel', 'onClick']);
|
|
16
|
+
|
|
17
|
+
const text = () => local.text ?? 'Thinking';
|
|
18
|
+
const stopLabel = () => local.stopLabel ?? 'Answer now';
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div class={cn('flex w-full items-center justify-between', local.class)}>
|
|
22
|
+
<Show
|
|
23
|
+
when={local.onClick}
|
|
24
|
+
fallback={
|
|
25
|
+
<TextShimmer class="cursor-default font-medium">{text()}</TextShimmer>
|
|
26
|
+
}
|
|
27
|
+
>
|
|
28
|
+
<button
|
|
29
|
+
type="button"
|
|
30
|
+
onClick={local.onClick}
|
|
31
|
+
class="flex items-center gap-1 text-sm transition-opacity hover:opacity-80"
|
|
32
|
+
>
|
|
33
|
+
<TextShimmer class="font-medium">{text()}</TextShimmer>
|
|
34
|
+
<ChevronRight class="text-muted-foreground size-4" />
|
|
35
|
+
</button>
|
|
36
|
+
</Show>
|
|
37
|
+
<Show when={local.onStop}>
|
|
38
|
+
<button
|
|
39
|
+
onClick={local.onStop}
|
|
40
|
+
type="button"
|
|
41
|
+
class="text-muted-foreground hover:text-foreground border-muted-foreground/50 hover:border-foreground border-b border-dotted text-sm transition-colors"
|
|
42
|
+
>
|
|
43
|
+
{stopLabel()}
|
|
44
|
+
</button>
|
|
45
|
+
</Show>
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { ThinkingBar };
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { Tool } from './tool';
|
|
3
|
+
import type { ToolPart } from './tool';
|
|
4
|
+
|
|
5
|
+
const streamingPart: ToolPart = {
|
|
6
|
+
type: 'search_documents',
|
|
7
|
+
state: 'input-streaming',
|
|
8
|
+
input: { query: 'SolidJS reactive primitives' },
|
|
9
|
+
toolCallId: 'call_abc123',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const readyPart: ToolPart = {
|
|
13
|
+
type: 'search_documents',
|
|
14
|
+
state: 'input-available',
|
|
15
|
+
input: { query: 'SolidJS reactive primitives', limit: 10 },
|
|
16
|
+
toolCallId: 'call_abc123',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const completedPart: ToolPart = {
|
|
20
|
+
type: 'search_documents',
|
|
21
|
+
state: 'output-available',
|
|
22
|
+
input: { query: 'SolidJS reactive primitives', limit: 10 },
|
|
23
|
+
output: { results: [{ title: 'Signals', score: 0.95 }, { title: 'Effects', score: 0.87 }] },
|
|
24
|
+
toolCallId: 'call_abc123',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const errorPart: ToolPart = {
|
|
28
|
+
type: 'search_documents',
|
|
29
|
+
state: 'output-error',
|
|
30
|
+
input: { query: 'SolidJS reactive primitives' },
|
|
31
|
+
errorText: 'Connection timeout: unable to reach the search service after 30 seconds.',
|
|
32
|
+
toolCallId: 'call_abc123',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const meta = {
|
|
36
|
+
title: 'Components/Tool',
|
|
37
|
+
component: Tool,
|
|
38
|
+
tags: ['autodocs'],
|
|
39
|
+
parameters: {
|
|
40
|
+
layout: 'padded',
|
|
41
|
+
docs: {
|
|
42
|
+
controls: { exclude: ['use:eventListener'] },
|
|
43
|
+
description: {
|
|
44
|
+
component: [
|
|
45
|
+
'A collapsible panel that visualizes a single tool call — its name, state (processing / ready / completed / error), input, output, error, and call ID.',
|
|
46
|
+
'**When to use:** to surface assistant tool/function calls in the conversation, so users can inspect what was run and what came back.',
|
|
47
|
+
'**How to use:** pass a `toolPart` describing the call (`type`, `state`, optional `input`, `output`, `errorText`, `toolCallId`). State drives the icon and badge automatically. Set `defaultOpen` to start expanded.',
|
|
48
|
+
'**Placement:** inline within an assistant message, typically between text segments where the tool was invoked.',
|
|
49
|
+
].join('\n\n'),
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
argTypes: {
|
|
54
|
+
toolPart: {
|
|
55
|
+
control: 'object',
|
|
56
|
+
description: 'The tool call to render — `type`, `state`, and optional `input`/`output`/`errorText`/`toolCallId`.',
|
|
57
|
+
},
|
|
58
|
+
defaultOpen: {
|
|
59
|
+
control: 'boolean',
|
|
60
|
+
description: 'Whether the panel starts expanded.',
|
|
61
|
+
table: { defaultValue: { summary: 'false' } },
|
|
62
|
+
},
|
|
63
|
+
class: {
|
|
64
|
+
control: 'text',
|
|
65
|
+
description: 'Additional CSS classes for the container.',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
args: {
|
|
69
|
+
toolPart: completedPart,
|
|
70
|
+
defaultOpen: true,
|
|
71
|
+
},
|
|
72
|
+
render: (args) => <Tool {...args} />,
|
|
73
|
+
} satisfies Meta<typeof Tool>;
|
|
74
|
+
|
|
75
|
+
export default meta;
|
|
76
|
+
type Story = StoryObj<typeof meta>;
|
|
77
|
+
|
|
78
|
+
const IMPORT = `import { Tool } from '@kitnai/chat';`;
|
|
79
|
+
const src = (code: string) => ({
|
|
80
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
/** Interactive playground — edit the `toolPart` object to explore every state. */
|
|
84
|
+
export const Playground: Story = {
|
|
85
|
+
...src(`<Tool
|
|
86
|
+
toolPart={{
|
|
87
|
+
type: 'search_documents',
|
|
88
|
+
state: 'output-available',
|
|
89
|
+
input: { query: 'SolidJS reactive primitives', limit: 10 },
|
|
90
|
+
output: { results: [{ title: 'Signals', score: 0.95 }] },
|
|
91
|
+
toolCallId: 'call_abc123',
|
|
92
|
+
}}
|
|
93
|
+
defaultOpen
|
|
94
|
+
/>`),
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const Processing: Story = {
|
|
98
|
+
args: { toolPart: streamingPart, defaultOpen: true },
|
|
99
|
+
...src(`<Tool
|
|
100
|
+
toolPart={{
|
|
101
|
+
type: 'search_documents',
|
|
102
|
+
state: 'input-streaming',
|
|
103
|
+
input: { query: 'SolidJS reactive primitives' },
|
|
104
|
+
toolCallId: 'call_abc123',
|
|
105
|
+
}}
|
|
106
|
+
defaultOpen
|
|
107
|
+
/>`),
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export const Ready: Story = {
|
|
111
|
+
args: { toolPart: readyPart, defaultOpen: true },
|
|
112
|
+
...src(`<Tool
|
|
113
|
+
toolPart={{
|
|
114
|
+
type: 'search_documents',
|
|
115
|
+
state: 'input-available',
|
|
116
|
+
input: { query: 'SolidJS reactive primitives', limit: 10 },
|
|
117
|
+
toolCallId: 'call_abc123',
|
|
118
|
+
}}
|
|
119
|
+
defaultOpen
|
|
120
|
+
/>`),
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export const Completed: Story = {
|
|
124
|
+
args: { toolPart: completedPart, defaultOpen: true },
|
|
125
|
+
...src(`<Tool
|
|
126
|
+
toolPart={{
|
|
127
|
+
type: 'search_documents',
|
|
128
|
+
state: 'output-available',
|
|
129
|
+
input: { query: 'SolidJS reactive primitives', limit: 10 },
|
|
130
|
+
output: { results: [{ title: 'Signals', score: 0.95 }, { title: 'Effects', score: 0.87 }] },
|
|
131
|
+
toolCallId: 'call_abc123',
|
|
132
|
+
}}
|
|
133
|
+
defaultOpen
|
|
134
|
+
/>`),
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export const Error: Story = {
|
|
138
|
+
args: { toolPart: errorPart, defaultOpen: true },
|
|
139
|
+
...src(`<Tool
|
|
140
|
+
toolPart={{
|
|
141
|
+
type: 'search_documents',
|
|
142
|
+
state: 'output-error',
|
|
143
|
+
input: { query: 'SolidJS reactive primitives' },
|
|
144
|
+
errorText: 'Connection timeout: unable to reach the search service after 30 seconds.',
|
|
145
|
+
toolCallId: 'call_abc123',
|
|
146
|
+
}}
|
|
147
|
+
defaultOpen
|
|
148
|
+
/>`),
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export const Collapsed: Story = {
|
|
152
|
+
args: { toolPart: completedPart, defaultOpen: false },
|
|
153
|
+
...src(`<Tool toolPart={toolPart} />`),
|
|
154
|
+
};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { type JSX, splitProps, createSignal, Show, For } from 'solid-js';
|
|
2
|
+
import { cn } from '../utils/cn';
|
|
3
|
+
import { Collapsible, CollapsibleTrigger, CollapsibleContent } from '../ui/collapsible';
|
|
4
|
+
import { Button } from '../ui/button';
|
|
5
|
+
import { CheckCircle, ChevronDown, Loader2, Settings, XCircle } from 'lucide-solid';
|
|
6
|
+
|
|
7
|
+
export interface ToolPart {
|
|
8
|
+
type: string;
|
|
9
|
+
state: 'input-streaming' | 'input-available' | 'output-available' | 'output-error';
|
|
10
|
+
input?: Record<string, unknown>;
|
|
11
|
+
output?: Record<string, unknown>;
|
|
12
|
+
toolCallId?: string;
|
|
13
|
+
errorText?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ToolProps {
|
|
17
|
+
toolPart: ToolPart;
|
|
18
|
+
defaultOpen?: boolean;
|
|
19
|
+
class?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function formatValue(value: unknown): string {
|
|
23
|
+
if (value === null) return 'null';
|
|
24
|
+
if (value === undefined) return 'undefined';
|
|
25
|
+
if (typeof value === 'string') return value;
|
|
26
|
+
if (typeof value === 'object') return JSON.stringify(value, null, 2);
|
|
27
|
+
return String(value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function ToolStateIcon(props: { state: ToolPart['state'] }) {
|
|
31
|
+
return (
|
|
32
|
+
<>
|
|
33
|
+
<Show when={props.state === 'input-streaming'}>
|
|
34
|
+
<Loader2 class="size-4 animate-spin text-blue-500" />
|
|
35
|
+
</Show>
|
|
36
|
+
<Show when={props.state === 'input-available'}>
|
|
37
|
+
<Settings class="size-4 text-orange-500" />
|
|
38
|
+
</Show>
|
|
39
|
+
<Show when={props.state === 'output-available'}>
|
|
40
|
+
<CheckCircle class="size-4 text-green-500" />
|
|
41
|
+
</Show>
|
|
42
|
+
<Show when={props.state === 'output-error'}>
|
|
43
|
+
<XCircle class="size-4 text-red-500" />
|
|
44
|
+
</Show>
|
|
45
|
+
</>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Status chips: a saturated hue as text over a 15% translucent fill of the same
|
|
50
|
+
// hue. This reads on both light and dark surfaces (mirroring the inline-code chip),
|
|
51
|
+
// so it needs no `dark:` variant — which wouldn't follow a token-scoped theme anyway.
|
|
52
|
+
const STATE_HUE: Record<ToolPart['state'], string> = {
|
|
53
|
+
'input-streaming': 'hsl(217 91% 60%)', // blue
|
|
54
|
+
'input-available': 'hsl(38 92% 50%)', // amber
|
|
55
|
+
'output-available': 'hsl(142 71% 45%)', // green
|
|
56
|
+
'output-error': 'hsl(0 84% 60%)', // red
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
function stateChip(state: ToolPart['state']): JSX.CSSProperties {
|
|
60
|
+
const hue = STATE_HUE[state];
|
|
61
|
+
return { color: hue, background: `color-mix(in oklab, ${hue} 15%, transparent)` };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function ToolStateBadge(props: { state: ToolPart['state'] }) {
|
|
65
|
+
const baseClasses = 'px-2 py-1 rounded-full text-xs font-medium';
|
|
66
|
+
return (
|
|
67
|
+
<>
|
|
68
|
+
<Show when={props.state === 'input-streaming'}>
|
|
69
|
+
<span class={baseClasses} style={stateChip('input-streaming')}>
|
|
70
|
+
Processing
|
|
71
|
+
</span>
|
|
72
|
+
</Show>
|
|
73
|
+
<Show when={props.state === 'input-available'}>
|
|
74
|
+
<span class={baseClasses} style={stateChip('input-available')}>
|
|
75
|
+
Ready
|
|
76
|
+
</span>
|
|
77
|
+
</Show>
|
|
78
|
+
<Show when={props.state === 'output-available'}>
|
|
79
|
+
<span class={baseClasses} style={stateChip('output-available')}>
|
|
80
|
+
Completed
|
|
81
|
+
</span>
|
|
82
|
+
</Show>
|
|
83
|
+
<Show when={props.state === 'output-error'}>
|
|
84
|
+
<span class={baseClasses} style={stateChip('output-error')}>
|
|
85
|
+
Error
|
|
86
|
+
</span>
|
|
87
|
+
</Show>
|
|
88
|
+
</>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function Tool(props: ToolProps) {
|
|
93
|
+
const [local, rest] = splitProps(props, ['toolPart', 'defaultOpen', 'class']);
|
|
94
|
+
const [isOpen, setIsOpen] = createSignal(local.defaultOpen ?? false);
|
|
95
|
+
|
|
96
|
+
const state = () => local.toolPart.state;
|
|
97
|
+
const input = () => local.toolPart.input;
|
|
98
|
+
const output = () => local.toolPart.output;
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<div class={cn('mt-3 overflow-hidden rounded-lg bg-muted/30', local.class)}>
|
|
102
|
+
<Collapsible open={isOpen()} onOpenChange={setIsOpen}>
|
|
103
|
+
<CollapsibleTrigger
|
|
104
|
+
as={(triggerProps: JSX.HTMLAttributes<HTMLButtonElement>) => (
|
|
105
|
+
<Button
|
|
106
|
+
variant="ghost"
|
|
107
|
+
class="h-auto w-full justify-between rounded-b-none px-3 py-2 font-normal"
|
|
108
|
+
{...triggerProps}
|
|
109
|
+
>
|
|
110
|
+
<div class="flex items-center gap-2">
|
|
111
|
+
<ToolStateIcon state={state()} />
|
|
112
|
+
<span class="font-mono text-sm font-medium">{local.toolPart.type}</span>
|
|
113
|
+
<ToolStateBadge state={state()} />
|
|
114
|
+
</div>
|
|
115
|
+
<ChevronDown class={cn('size-4 transition-transform', isOpen() && 'rotate-180')} />
|
|
116
|
+
</Button>
|
|
117
|
+
)}
|
|
118
|
+
/>
|
|
119
|
+
<CollapsibleContent
|
|
120
|
+
class="data-[state=closed]:animate-collapsible-up data-[state=open]:animate-collapsible-down overflow-hidden"
|
|
121
|
+
>
|
|
122
|
+
<div class="space-y-3 p-3">
|
|
123
|
+
<Show when={input() && Object.keys(input()!).length > 0}>
|
|
124
|
+
<div>
|
|
125
|
+
<h4 class="text-muted-foreground mb-2 text-sm font-medium">Input</h4>
|
|
126
|
+
<div class="rounded bg-muted/50 p-2 font-mono text-sm">
|
|
127
|
+
<For each={Object.entries(input()!)}>
|
|
128
|
+
{([key, value]) => (
|
|
129
|
+
<div class="mb-1">
|
|
130
|
+
<span class="text-muted-foreground">{key}:</span>{' '}
|
|
131
|
+
<span>{formatValue(value)}</span>
|
|
132
|
+
</div>
|
|
133
|
+
)}
|
|
134
|
+
</For>
|
|
135
|
+
</div>
|
|
136
|
+
</div>
|
|
137
|
+
</Show>
|
|
138
|
+
|
|
139
|
+
<Show when={output()}>
|
|
140
|
+
<div>
|
|
141
|
+
<h4 class="text-muted-foreground mb-2 text-sm font-medium">Output</h4>
|
|
142
|
+
<div class="max-h-60 overflow-auto rounded bg-muted/50 p-2 font-mono text-sm">
|
|
143
|
+
<pre class="whitespace-pre-wrap">{formatValue(output())}</pre>
|
|
144
|
+
</div>
|
|
145
|
+
</div>
|
|
146
|
+
</Show>
|
|
147
|
+
|
|
148
|
+
<Show when={state() === 'output-error' && local.toolPart.errorText}>
|
|
149
|
+
<div>
|
|
150
|
+
<h4 class="mb-2 text-sm font-medium text-red-500">Error</h4>
|
|
151
|
+
<div class="rounded bg-red-500/10 p-2 text-sm">
|
|
152
|
+
{local.toolPart.errorText}
|
|
153
|
+
</div>
|
|
154
|
+
</div>
|
|
155
|
+
</Show>
|
|
156
|
+
|
|
157
|
+
<Show when={state() === 'input-streaming'}>
|
|
158
|
+
<div class="text-muted-foreground text-sm">Processing tool call...</div>
|
|
159
|
+
</Show>
|
|
160
|
+
|
|
161
|
+
<Show when={local.toolPart.toolCallId}>
|
|
162
|
+
<div class="text-muted-foreground pt-2 text-xs">
|
|
163
|
+
<span class="font-mono">Call ID: {local.toolPart.toolCallId}</span>
|
|
164
|
+
</div>
|
|
165
|
+
</Show>
|
|
166
|
+
</div>
|
|
167
|
+
</CollapsibleContent>
|
|
168
|
+
</Collapsible>
|
|
169
|
+
</div>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export { Tool };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { fn } from 'storybook/test';
|
|
3
|
+
import { VoiceInput } from './voice-input';
|
|
4
|
+
|
|
5
|
+
/** Sample transcription handler — resolves the recorded audio to text. */
|
|
6
|
+
const transcribe = async (_audio: Blob): Promise<string> => {
|
|
7
|
+
await new Promise((r) => setTimeout(r, 1200));
|
|
8
|
+
return 'Hello from the microphone';
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const meta = {
|
|
12
|
+
title: 'Components/VoiceInput',
|
|
13
|
+
component: VoiceInput,
|
|
14
|
+
tags: ['autodocs'],
|
|
15
|
+
parameters: {
|
|
16
|
+
layout: 'padded',
|
|
17
|
+
docs: {
|
|
18
|
+
controls: { exclude: ['use:eventListener'] },
|
|
19
|
+
description: {
|
|
20
|
+
component: [
|
|
21
|
+
'A microphone button that records audio, shows recording (pulse rings) and processing (spinner) states, then hands the audio off for transcription.',
|
|
22
|
+
'**When to use:** to let users dictate input by voice instead of typing — speech-to-text for the prompt field.',
|
|
23
|
+
'**How to use:** provide `onTranscribe(audio)` returning a `Promise<string>` (your STT call) and `onTranscription(text)` to receive the result. Click toggles recording; transcription runs automatically on stop. Set `disabled` to block input.',
|
|
24
|
+
'**Placement:** inside the prompt input action bar, next to send and other input actions.',
|
|
25
|
+
].join('\n\n'),
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
argTypes: {
|
|
30
|
+
disabled: {
|
|
31
|
+
control: 'boolean',
|
|
32
|
+
description: 'Disables the button (also disabled while transcribing).',
|
|
33
|
+
table: { defaultValue: { summary: 'false' } },
|
|
34
|
+
},
|
|
35
|
+
class: {
|
|
36
|
+
control: 'text',
|
|
37
|
+
description: 'Additional CSS classes for the container.',
|
|
38
|
+
},
|
|
39
|
+
onTranscribe: {
|
|
40
|
+
action: 'transcribe',
|
|
41
|
+
description: 'Receives the recorded audio `Blob` and must resolve to the transcribed text.',
|
|
42
|
+
table: { category: 'Events' },
|
|
43
|
+
},
|
|
44
|
+
onTranscription: {
|
|
45
|
+
action: 'transcription',
|
|
46
|
+
description: 'Called with the final transcribed text (trimmed, non-empty).',
|
|
47
|
+
table: { category: 'Events' },
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
args: {
|
|
51
|
+
disabled: false,
|
|
52
|
+
onTranscribe: transcribe,
|
|
53
|
+
onTranscription: fn(),
|
|
54
|
+
},
|
|
55
|
+
render: (args) => <VoiceInput {...args} />,
|
|
56
|
+
} satisfies Meta<typeof VoiceInput>;
|
|
57
|
+
|
|
58
|
+
export default meta;
|
|
59
|
+
type Story = StoryObj<typeof meta>;
|
|
60
|
+
|
|
61
|
+
const IMPORT = `import { VoiceInput } from '@kitnai/chat';`;
|
|
62
|
+
const src = (code: string) => ({
|
|
63
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
/** Interactive playground — click the mic to record (requires mic permission). */
|
|
67
|
+
export const Playground: Story = {
|
|
68
|
+
...src(`<VoiceInput
|
|
69
|
+
onTranscribe={async (audio) => {
|
|
70
|
+
const res = await transcribeAudio(audio); // your STT call
|
|
71
|
+
return res.text;
|
|
72
|
+
}}
|
|
73
|
+
onTranscription={(text) => setInput((v) => v + text)}
|
|
74
|
+
/>`),
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const Disabled: Story = {
|
|
78
|
+
args: { disabled: true },
|
|
79
|
+
...src(`<VoiceInput
|
|
80
|
+
disabled
|
|
81
|
+
onTranscribe={transcribe}
|
|
82
|
+
onTranscription={(text) => setInput(text)}
|
|
83
|
+
/>`),
|
|
84
|
+
};
|