@kitn.ai/ui 0.14.1 → 0.15.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.
Files changed (179) hide show
  1. package/dist/kitn-chat.es.js +1 -1
  2. package/package.json +6 -1
  3. package/src/components/component-meta.json +10 -10
  4. package/src/elements/compiled.css +1 -1
  5. package/src/remote/host-embed.ts +1 -1
  6. package/src/components/artifact.stories.tsx +0 -138
  7. package/src/components/attachments.stories.tsx +0 -303
  8. package/src/components/attachments.test.tsx +0 -64
  9. package/src/components/chain-of-thought.stories.tsx +0 -211
  10. package/src/components/chat-container.stories.tsx +0 -187
  11. package/src/components/chat-thread.test.tsx +0 -58
  12. package/src/components/checkpoint.stories.tsx +0 -102
  13. package/src/components/code-block.stories.tsx +0 -150
  14. package/src/components/confirm-card.stories.tsx +0 -74
  15. package/src/components/context.stories.tsx +0 -229
  16. package/src/components/context.test.tsx +0 -133
  17. package/src/components/conversation-item.stories.tsx +0 -125
  18. package/src/components/conversation-list.stories.tsx +0 -133
  19. package/src/components/default-input.test.tsx +0 -111
  20. package/src/components/empty.stories.tsx +0 -434
  21. package/src/components/feedback-bar.stories.tsx +0 -138
  22. package/src/components/feedback-bar.test.tsx +0 -103
  23. package/src/components/file-tree.stories.tsx +0 -73
  24. package/src/components/file-upload.stories.tsx +0 -156
  25. package/src/components/image.stories.tsx +0 -89
  26. package/src/components/loader.stories.tsx +0 -181
  27. package/src/components/markdown.stories.tsx +0 -180
  28. package/src/components/message-action-bar.test.tsx +0 -128
  29. package/src/components/message-narrow.stories.tsx +0 -329
  30. package/src/components/message-skills.stories.tsx +0 -211
  31. package/src/components/message.stories.tsx +0 -281
  32. package/src/components/model-switcher.stories.tsx +0 -123
  33. package/src/components/model-switcher.test.tsx +0 -65
  34. package/src/components/prompt-input.stories.tsx +0 -222
  35. package/src/components/prompt-suggestion.stories.tsx +0 -142
  36. package/src/components/reasoning.stories.tsx +0 -140
  37. package/src/components/resizable.test.tsx +0 -226
  38. package/src/components/scroll-button.stories.tsx +0 -100
  39. package/src/components/slash-command.stories.tsx +0 -163
  40. package/src/components/source-list.test.tsx +0 -152
  41. package/src/components/source.stories.tsx +0 -124
  42. package/src/components/tasks-card.stories.tsx +0 -78
  43. package/src/components/text-shimmer.stories.tsx +0 -87
  44. package/src/components/thinking-bar.stories.tsx +0 -87
  45. package/src/components/tool.stories.tsx +0 -153
  46. package/src/components/voice-input.stories.tsx +0 -83
  47. package/src/elements/artifact.stories.tsx +0 -506
  48. package/src/elements/attachments.stories.tsx +0 -190
  49. package/src/elements/card.stories.tsx +0 -113
  50. package/src/elements/cards.stories.tsx +0 -59
  51. package/src/elements/catalog.stories.tsx +0 -491
  52. package/src/elements/chain-of-thought.declarative.test.tsx +0 -153
  53. package/src/elements/chain-of-thought.stories.tsx +0 -113
  54. package/src/elements/chat-scope-picker.stories.tsx +0 -73
  55. package/src/elements/chat-workspace.stories.tsx +0 -288
  56. package/src/elements/chat.stories.tsx +0 -151
  57. package/src/elements/checkpoint.stories.tsx +0 -72
  58. package/src/elements/choice.stories.tsx +0 -240
  59. package/src/elements/code-block.stories.tsx +0 -83
  60. package/src/elements/composed-shell.stories.tsx +0 -316
  61. package/src/elements/confirm-card.stories.tsx +0 -227
  62. package/src/elements/context-meter.stories.tsx +0 -151
  63. package/src/elements/conversation-list.declarative.test.tsx +0 -137
  64. package/src/elements/conversation-list.stories.tsx +0 -243
  65. package/src/elements/embed.stories.tsx +0 -213
  66. package/src/elements/empty.stories.tsx +0 -111
  67. package/src/elements/feedback-bar.stories.tsx +0 -114
  68. package/src/elements/file-tree.stories.tsx +0 -134
  69. package/src/elements/file-upload.stories.tsx +0 -82
  70. package/src/elements/form.stories.tsx +0 -248
  71. package/src/elements/image.stories.tsx +0 -71
  72. package/src/elements/link-preview.stories.tsx +0 -209
  73. package/src/elements/loader.stories.tsx +0 -88
  74. package/src/elements/markdown.stories.tsx +0 -76
  75. package/src/elements/message-skills.declarative.test.tsx +0 -104
  76. package/src/elements/message-skills.stories.tsx +0 -114
  77. package/src/elements/message.stories.tsx +0 -218
  78. package/src/elements/model-switcher.declarative.test.tsx +0 -130
  79. package/src/elements/model-switcher.stories.tsx +0 -198
  80. package/src/elements/popover.stories.tsx +0 -80
  81. package/src/elements/prompt-input-slash-command.test.tsx +0 -128
  82. package/src/elements/prompt-input-stoppable.test.tsx +0 -88
  83. package/src/elements/prompt-input-toolbar-actions.test.tsx +0 -120
  84. package/src/elements/prompt-input.stories.tsx +0 -331
  85. package/src/elements/prompt-suggestions.declarative.test.tsx +0 -164
  86. package/src/elements/prompt-suggestions.stories.tsx +0 -213
  87. package/src/elements/reasoning.stories.tsx +0 -77
  88. package/src/elements/remote.stories.tsx +0 -314
  89. package/src/elements/resizable.stories.tsx +0 -426
  90. package/src/elements/response-stream.stories.tsx +0 -79
  91. package/src/elements/scroll-button.stories.tsx +0 -202
  92. package/src/elements/scroll-button.test.tsx +0 -148
  93. package/src/elements/source-list.stories.tsx +0 -143
  94. package/src/elements/source.stories.tsx +0 -88
  95. package/src/elements/switch.stories.tsx +0 -56
  96. package/src/elements/tasks.stories.tsx +0 -237
  97. package/src/elements/text-shimmer.stories.tsx +0 -64
  98. package/src/elements/thinking-bar.stories.tsx +0 -72
  99. package/src/elements/tool.stories.tsx +0 -89
  100. package/src/elements/voice-input.stories.tsx +0 -88
  101. package/src/primitives/controllable.test.ts +0 -47
  102. package/src/stories/chat-panel-layout.stories.tsx +0 -145
  103. package/src/stories/chat-scene.tsx +0 -571
  104. package/src/stories/checkpoint-restore.stories.tsx +0 -256
  105. package/src/stories/context-usage.stories.tsx +0 -212
  106. package/src/stories/conversation-with-reasoning.stories.tsx +0 -182
  107. package/src/stories/conversation-with-sources.stories.tsx +0 -471
  108. package/src/stories/docs/Accessibility.mdx +0 -119
  109. package/src/stories/docs/ChildElements.mdx +0 -269
  110. package/src/stories/docs/ForAIAgents.mdx +0 -162
  111. package/src/stories/docs/GettingStarted.mdx +0 -65
  112. package/src/stories/docs/Installation.mdx +0 -83
  113. package/src/stories/docs/Introduction.mdx +0 -50
  114. package/src/stories/docs/SolidJsAdvanced.mdx +0 -17
  115. package/src/stories/docs/Theming.mdx +0 -85
  116. package/src/stories/docs/element-controls.ts +0 -121
  117. package/src/stories/docs/frameworks/Angular.mdx +0 -245
  118. package/src/stories/docs/frameworks/Html.mdx +0 -227
  119. package/src/stories/docs/frameworks/Overview.mdx +0 -47
  120. package/src/stories/docs/frameworks/React.mdx +0 -227
  121. package/src/stories/docs/frameworks/Solid.mdx +0 -173
  122. package/src/stories/docs/frameworks/Svelte.mdx +0 -194
  123. package/src/stories/docs/frameworks/Vue.mdx +0 -238
  124. package/src/stories/docs/generative-ui-overview.mdx +0 -186
  125. package/src/stories/docs/recipes/SpeechToText.mdx +0 -7
  126. package/src/stories/docs/recipes/Streaming.mdx +0 -68
  127. package/src/stories/docs/recipes/TextToSpeech.mdx +0 -35
  128. package/src/stories/docs/theme-editor/canvas.tsx +0 -32
  129. package/src/stories/docs/theme-editor/inspector.tsx +0 -66
  130. package/src/stories/docs/theme-editor/presets.test.ts +0 -32
  131. package/src/stories/docs/theme-editor/presets.ts +0 -64
  132. package/src/stories/docs/theme-editor/theme-css.test.ts +0 -19
  133. package/src/stories/docs/theme-editor/theme-css.ts +0 -15
  134. package/src/stories/docs/theme-editor/theme-editor.tsx +0 -146
  135. package/src/stories/docs/theme-tokens.tsx +0 -174
  136. package/src/stories/examples/ChoosingComponents.mdx +0 -106
  137. package/src/stories/examples/sample-data.ts +0 -79
  138. package/src/stories/examples/usage/checkpoint-restore.ts +0 -156
  139. package/src/stories/examples/usage/context-usage.ts +0 -591
  140. package/src/stories/examples/usage/conversation-with-reasoning.ts +0 -224
  141. package/src/stories/examples/usage/conversation-with-sources.ts +0 -589
  142. package/src/stories/examples/usage/empty-state.ts +0 -144
  143. package/src/stories/examples/usage/full-chat-app.ts +0 -277
  144. package/src/stories/examples/usage/index.ts +0 -63
  145. package/src/stories/examples/usage/message-actions.ts +0 -704
  146. package/src/stories/examples/usage/pattern-centered-conversation.ts +0 -446
  147. package/src/stories/examples/usage/pattern-chat-panel-layout.ts +0 -442
  148. package/src/stories/examples/usage/pattern-docked-widget.ts +0 -479
  149. package/src/stories/examples/usage/prompt-input-variants.ts +0 -1356
  150. package/src/stories/examples/usage/streaming-response.ts +0 -687
  151. package/src/stories/examples/usage/types.ts +0 -33
  152. package/src/stories/full-chat.stories.tsx +0 -18
  153. package/src/stories/message-actions.stories.tsx +0 -230
  154. package/src/stories/pattern-centered-conversation.stories.tsx +0 -93
  155. package/src/stories/pattern-docked-widget.stories.tsx +0 -93
  156. package/src/stories/pattern-empty-state.stories.tsx +0 -76
  157. package/src/stories/prompt-input-variants.stories.tsx +0 -456
  158. package/src/stories/streaming-response.stories.tsx +0 -438
  159. package/src/stories/theme-editor.stories.tsx +0 -16
  160. package/src/stories/token-reference.stories.tsx +0 -18
  161. package/src/stories/typography.stories.tsx +0 -78
  162. package/src/ui/avatar.stories.tsx +0 -103
  163. package/src/ui/badge.stories.tsx +0 -86
  164. package/src/ui/button.stories.tsx +0 -145
  165. package/src/ui/collapsible.stories.tsx +0 -69
  166. package/src/ui/dropdown.stories.tsx +0 -59
  167. package/src/ui/hover-card.stories.tsx +0 -77
  168. package/src/ui/hover-card.test.tsx +0 -30
  169. package/src/ui/overlay.stories.tsx +0 -115
  170. package/src/ui/popover.stories.tsx +0 -81
  171. package/src/ui/popover.test.tsx +0 -99
  172. package/src/ui/resizable.stories.tsx +0 -236
  173. package/src/ui/scroll-area.stories.tsx +0 -50
  174. package/src/ui/separator.stories.tsx +0 -81
  175. package/src/ui/skeleton.stories.tsx +0 -337
  176. package/src/ui/switch.stories.tsx +0 -51
  177. package/src/ui/switch.test.tsx +0 -59
  178. package/src/ui/textarea.stories.tsx +0 -76
  179. package/src/ui/tooltip.stories.tsx +0 -74
@@ -1,151 +0,0 @@
1
- import type { Meta, StoryObj } from 'storybook-solidjs-vite';
2
- import { onMount } from 'solid-js';
3
- import './register'; // side effect: registers the custom elements
4
- import { argTypesFor, specDescription } from '../stories/docs/element-controls';
5
-
6
- interface ContextUsage {
7
- usedTokens: number;
8
- maxTokens: number;
9
- inputTokens?: number;
10
- outputTokens?: number;
11
- reasoningTokens?: number;
12
- cacheTokens?: number;
13
- estimatedCost?: number;
14
- }
15
-
16
- // The web components are custom DOM elements, so declare the tags for JSX.
17
- declare module 'solid-js' {
18
- // eslint-disable-next-line @typescript-eslint/no-namespace
19
- namespace JSX {
20
- interface IntrinsicElements {
21
- 'kai-context': JSX.HTMLAttributes<HTMLElement>;
22
- }
23
- }
24
- }
25
-
26
- const usage: ContextUsage = {
27
- usedTokens: 48200,
28
- maxTokens: 200000,
29
- inputTokens: 31000,
30
- outputTokens: 17200,
31
- reasoningTokens: 4200,
32
- cacheTokens: 8000,
33
- estimatedCost: 0.42,
34
- };
35
-
36
- interface MeterElementProps {
37
- context: ContextUsage;
38
- warnThreshold?: number;
39
- dangerThreshold?: number;
40
- onThresholdChange?: (level: string) => void;
41
- }
42
-
43
- /** Render `<kai-context>` with the `context` set as a JS property. */
44
- function MeterElement(props: MeterElementProps) {
45
- let el: (HTMLElement & { context?: ContextUsage; warnThreshold?: number; dangerThreshold?: number }) | undefined;
46
- onMount(() => {
47
- if (!el) return;
48
- el.context = props.context;
49
- if (props.warnThreshold !== undefined) el.warnThreshold = props.warnThreshold;
50
- if (props.dangerThreshold !== undefined) el.dangerThreshold = props.dangerThreshold;
51
- if (props.onThresholdChange) {
52
- el.addEventListener('kai-threshold-change', (e) => {
53
- props.onThresholdChange!((e as CustomEvent<{ level: string }>).detail.level);
54
- });
55
- }
56
- });
57
- return (
58
- <kai-context ref={(e) => (el = e as HTMLElement)} style={{ display: 'inline-block', padding: '40px' }} />
59
- );
60
- }
61
-
62
- const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
63
- <kai-context id="ctx"></kai-context>
64
-
65
- <script type="module">
66
- import '@kitn.ai/ui/elements'; // registers the custom elements
67
-
68
- document.getElementById('ctx').context = {
69
- usedTokens: 48200, maxTokens: 200000,
70
- inputTokens: 31000, outputTokens: 17200,
71
- reasoningTokens: 4200, cacheTokens: 8000,
72
- estimatedCost: 0.42,
73
- };
74
- </script>`;
75
-
76
- const CUSTOM_THRESHOLDS_SNIPPET = `<!-- Custom thresholds: warn at 50%, danger at 75% -->
77
- <kai-context id="ctx"></kai-context>
78
-
79
- <script type="module">
80
- import '@kitn.ai/ui/elements';
81
-
82
- const el = document.getElementById('ctx');
83
- el.context = {
84
- usedTokens: 110000, // 55% of 200 000 -> warn (> 50%)
85
- maxTokens: 200000,
86
- inputTokens: 70000,
87
- outputTokens: 40000,
88
- estimatedCost: 0.65,
89
- };
90
-
91
- // Lower the thresholds so the indicator warns earlier.
92
- el.warnThreshold = 0.5; // default 0.7
93
- el.dangerThreshold = 0.75; // default 0.9
94
-
95
- // Listen for severity changes.
96
- el.addEventListener('kai-threshold-change', (e) => {
97
- console.log('severity changed to', e.detail.level); // 'ok' | 'warn' | 'danger'
98
- });
99
- </script>`;
100
-
101
- const meta = {
102
- title: 'Components/Context',
103
- tags: ['autodocs'],
104
- argTypes: argTypesFor('kai-context'),
105
- parameters: {
106
- layout: 'fullscreen',
107
- docs: {
108
- description: specDescription('kai-context', [
109
- '`<kai-context>` is the framework-agnostic **web component** for a token/context-window usage meter — a compact gauge with a hover-card breakdown (input / output / reasoning / cache + estimated cost) — isolated in **Shadow DOM**.',
110
- '**When to use:** showing how much of the context window a conversation is using, typically in a chat header. In SolidJS, compose the `Context` primitives.',
111
- '**Placement:** inline in the chat header or toolbar, beside the model switcher or other header controls; it is a compact `inline-block` element and does not need a dedicated row.',
112
- "**How to use:** register once with `import '@kitn.ai/ui/elements'`, then set the `context` **property** with the usage object. Hover the meter to reveal the breakdown.",
113
- '**Color thresholds** are configurable via `warnThreshold` (default `0.7`) and `dangerThreshold` (default `0.9`) number properties. When the computed severity level changes, the element fires a **`kai-threshold-change`** event with `detail.level` set to `\'ok\'`, `\'warn\'`, or `\'danger\'`.',
114
- 'See the **Code** tab for HTML usage.',
115
- ]),
116
- },
117
- },
118
- } satisfies Meta;
119
-
120
- export default meta;
121
- type Story = StoryObj;
122
-
123
- /** A meter at ~24% usage; hover to reveal the full breakdown. */
124
- export const Default: Story = {
125
- render: () => <MeterElement context={usage} />,
126
- parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
127
- };
128
-
129
- /**
130
- * Custom thresholds — `warnThreshold=0.5` and `dangerThreshold=0.75` so the
131
- * meter turns yellow at 50% and red at 75%. At ~55% (110 000 / 200 000) the
132
- * meter renders yellow. Open the browser console to see `kai-threshold-change`
133
- * events as the property changes.
134
- */
135
- export const CustomThresholds: Story = {
136
- render: () => (
137
- <MeterElement
138
- context={{
139
- usedTokens: 110000,
140
- maxTokens: 200000,
141
- inputTokens: 70000,
142
- outputTokens: 40000,
143
- estimatedCost: 0.65,
144
- }}
145
- warnThreshold={0.5}
146
- dangerThreshold={0.75}
147
- onThresholdChange={(level) => console.log('kai-threshold-change', { level })}
148
- />
149
- ),
150
- parameters: { docs: { source: { code: CUSTOM_THRESHOLDS_SNIPPET, language: 'html' } } },
151
- };
@@ -1,137 +0,0 @@
1
- /**
2
- * Unit tests for the declarative `<kai-conversation>` light-DOM API of
3
- * `<kai-conversations>`.
4
- *
5
- * Strategy: `defineWebComponent` registers a real Shadow-DOM custom element
6
- * and is not suitable for jsdom unit tests. Instead:
7
- * 1. Test the exported `parseKaiConversationElement` helper in isolation.
8
- * 2. Test that the merged list of prop + slotted items renders items correctly
9
- * via a minimal ConvList harness, mirroring the pattern in
10
- * `source-list.test.tsx`.
11
- */
12
- import { describe, it, expect, vi, afterEach } from 'vitest';
13
- import '@testing-library/jest-dom/vitest';
14
- import { render, cleanup, fireEvent } from '@solidjs/testing-library';
15
- import { For } from 'solid-js';
16
- import { parseKaiConversationElement } from './conversation-list';
17
- import type { ConversationSummary } from '../types';
18
-
19
- afterEach(cleanup);
20
-
21
- // ---------------------------------------------------------------------------
22
- // parseKaiConversationElement — pure helper
23
- // ---------------------------------------------------------------------------
24
-
25
- describe('parseKaiConversationElement', () => {
26
- function makeEl(attrs: Record<string, string | null>, textContent = ''): Element {
27
- const el = document.createElement('kai-conversation');
28
- for (const [k, v] of Object.entries(attrs)) {
29
- if (v !== null) el.setAttribute(k, v);
30
- }
31
- el.textContent = textContent;
32
- return el;
33
- }
34
-
35
- it('maps id attribute to ConversationSummary.id', () => {
36
- const el = makeEl({ id: 'c-1' }, 'Q2 plan');
37
- expect(parseKaiConversationElement(el).id).toBe('c-1');
38
- });
39
-
40
- it('uses trimmed textContent as title', () => {
41
- const el = makeEl({ id: 'c-1' }, ' Q2 plan ');
42
- expect(parseKaiConversationElement(el).title).toBe('Q2 plan');
43
- });
44
-
45
- it('reads group-id attribute as groupId when present', () => {
46
- const el = makeEl({ id: 'c-1', 'group-id': 'g-work' }, 'Q2 plan');
47
- expect(parseKaiConversationElement(el).groupId).toBe('g-work');
48
- });
49
-
50
- it('sets groupId to undefined when group-id attribute is absent', () => {
51
- const el = makeEl({ id: 'c-1' }, 'Q2 plan');
52
- expect(parseKaiConversationElement(el).groupId).toBeUndefined();
53
- });
54
-
55
- it('falls back to empty string for missing id attribute', () => {
56
- const el = makeEl({}, 'Untitled');
57
- expect(parseKaiConversationElement(el).id).toBe('');
58
- });
59
-
60
- it('provides safe defaults for scope, messageCount, lastMessageAt, updatedAt', () => {
61
- const el = makeEl({ id: 'c-1' }, 'Q2 plan');
62
- const item = parseKaiConversationElement(el);
63
- expect(item.scope).toEqual({ type: 'collection' });
64
- expect(item.messageCount).toBe(0);
65
- expect(typeof item.lastMessageAt).toBe('string');
66
- expect(typeof item.updatedAt).toBe('string');
67
- });
68
- });
69
-
70
- // ---------------------------------------------------------------------------
71
- // Merge: prop conversations + slotted conversations combine correctly
72
- // ---------------------------------------------------------------------------
73
-
74
- describe('conversation merge order', () => {
75
- /** Minimal render harness that outputs a button per conversation. */
76
- function ConvList(props: { items: ConversationSummary[]; onSelect: (id: string) => void }) {
77
- return (
78
- <div>
79
- <For each={props.items}>
80
- {(c) => (
81
- <button type="button" onClick={() => props.onSelect(c.id)}>
82
- {c.title}
83
- </button>
84
- )}
85
- </For>
86
- </div>
87
- );
88
- }
89
-
90
- it('renders one item per conversation', () => {
91
- const items: ConversationSummary[] = [
92
- { id: 'c-1', title: 'First', scope: { type: 'collection' }, messageCount: 0, lastMessageAt: '', updatedAt: '' },
93
- { id: 'c-2', title: 'Second', scope: { type: 'collection' }, messageCount: 0, lastMessageAt: '', updatedAt: '' },
94
- ];
95
- const { getByText } = render(() => <ConvList items={items} onSelect={() => {}} />);
96
- expect(getByText('First')).toBeInTheDocument();
97
- expect(getByText('Second')).toBeInTheDocument();
98
- });
99
-
100
- it('fires onSelect with the conversation id when an item is clicked', () => {
101
- const onSelect = vi.fn();
102
- const items: ConversationSummary[] = [
103
- { id: 'c-42', title: 'API plan', scope: { type: 'collection' }, messageCount: 0, lastMessageAt: '', updatedAt: '' },
104
- ];
105
- const { getByText } = render(() => <ConvList items={items} onSelect={onSelect} />);
106
- fireEvent.click(getByText('API plan'));
107
- expect(onSelect).toHaveBeenCalledWith('c-42');
108
- });
109
-
110
- it('renders prop items before declarative (slotted) items', () => {
111
- const propItems: ConversationSummary[] = [
112
- { id: 'p-1', title: 'Prop conv', scope: { type: 'collection' }, messageCount: 0, lastMessageAt: '', updatedAt: '' },
113
- ];
114
- const slottedItems: ConversationSummary[] = [
115
- { id: 's-1', title: 'Slotted conv', scope: { type: 'collection' }, messageCount: 0, lastMessageAt: '', updatedAt: '' },
116
- ];
117
- const merged = [...propItems, ...slottedItems];
118
-
119
- const { getAllByRole } = render(() => <ConvList items={merged} onSelect={() => {}} />);
120
- const buttons = getAllByRole('button');
121
- expect(buttons).toHaveLength(2);
122
- expect(buttons[0]).toHaveTextContent('Prop conv');
123
- expect(buttons[1]).toHaveTextContent('Slotted conv');
124
- });
125
-
126
- it('parseKaiConversationElement produces items that render and fire correct id', () => {
127
- const onSelect = vi.fn();
128
- const el = document.createElement('kai-conversation');
129
- el.setAttribute('id', 'c-99');
130
- el.textContent = 'My conversation';
131
-
132
- const parsed = parseKaiConversationElement(el);
133
- const { getByText } = render(() => <ConvList items={[parsed]} onSelect={onSelect} />);
134
- fireEvent.click(getByText('My conversation'));
135
- expect(onSelect).toHaveBeenCalledWith('c-99');
136
- });
137
- });
@@ -1,243 +0,0 @@
1
- import type { Meta, StoryObj } from 'storybook-solidjs-vite';
2
- import { onMount } from 'solid-js';
3
- import './register'; // side effect: registers <kai-chat>, <kai-conversations>, <kai-prompt-input>
4
- import type { ConversationGroup, ConversationSummary } from '../types';
5
- import { argTypesFor, specDescription } from '../stories/docs/element-controls';
6
-
7
- // The web components are custom DOM elements, so declare the tags for JSX.
8
- declare module 'solid-js' {
9
- // eslint-disable-next-line @typescript-eslint/no-namespace
10
- namespace JSX {
11
- interface IntrinsicElements {
12
- 'kai-conversations': JSX.HTMLAttributes<HTMLElement>;
13
- 'kai-conversation': JSX.HTMLAttributes<HTMLElement> & { id?: string; 'group-id'?: string };
14
- }
15
- }
16
- }
17
-
18
- const sampleGroups: ConversationGroup[] = [
19
- { id: 'g-work', name: 'Work', sortOrder: 0, createdAt: '2026-06-01T09:00:00.000Z' },
20
- { id: 'g-personal', name: 'Personal', sortOrder: 1, createdAt: '2026-06-02T09:00:00.000Z' },
21
- ];
22
-
23
- const sampleConversations: ConversationSummary[] = [
24
- {
25
- id: 'c-1',
26
- title: 'Q2 launch plan',
27
- groupId: 'g-work',
28
- scope: { type: 'collection' },
29
- messageCount: 12,
30
- lastMessageAt: '2026-06-09T14:20:00.000Z',
31
- updatedAt: '2026-06-09T14:20:00.000Z',
32
- },
33
- {
34
- id: 'c-2',
35
- title: 'API migration notes',
36
- groupId: 'g-work',
37
- scope: { type: 'collection' },
38
- messageCount: 5,
39
- lastMessageAt: '2026-06-08T11:05:00.000Z',
40
- updatedAt: '2026-06-08T11:05:00.000Z',
41
- },
42
- {
43
- id: 'c-3',
44
- title: 'Weekend trip ideas',
45
- groupId: 'g-personal',
46
- scope: { type: 'collection' },
47
- messageCount: 8,
48
- lastMessageAt: '2026-06-07T19:42:00.000Z',
49
- updatedAt: '2026-06-07T19:42:00.000Z',
50
- },
51
- {
52
- id: 'c-4',
53
- title: 'Untitled chat',
54
- scope: { type: 'collection' },
55
- messageCount: 1,
56
- lastMessageAt: '2026-06-10T08:00:00.000Z',
57
- updatedAt: '2026-06-10T08:00:00.000Z',
58
- },
59
- ];
60
-
61
- type ConversationListEl = HTMLElement & {
62
- groups?: ConversationGroup[];
63
- conversations?: ConversationSummary[];
64
- activeId?: string;
65
- };
66
-
67
- /** Live demo of the actual `<kai-conversations>` custom element (Shadow DOM and all). */
68
- function ConversationListElement(props: { args?: Record<string, unknown> }) {
69
- let el: ConversationListEl | undefined;
70
- onMount(() => {
71
- if (el) {
72
- // Fixed array data
73
- el.groups = sampleGroups;
74
- el.conversations = sampleConversations;
75
- el.activeId = 'c-1';
76
- // Scalar args from Controls
77
- const args = props.args;
78
- if (args) {
79
- const scalarNames = ['activeId'];
80
- for (const name of scalarNames) {
81
- if (name in args) (el as unknown as Record<string, unknown>)[name] = args[name];
82
- }
83
- }
84
- }
85
- });
86
- return (
87
- <kai-conversations
88
- ref={(e) => (el = e as ConversationListEl)}
89
- style={{ display: 'block', width: '300px', height: '560px' }}
90
- />
91
- );
92
- }
93
-
94
- const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
95
- <kai-conversations id="list" style="display:block; width:300px; height:100vh;"></kai-conversations>
96
-
97
- <script type="module">
98
- import '@kitn.ai/ui/elements'; // registers the custom elements
99
-
100
- const list = document.getElementById('list');
101
- list.groups = [
102
- { id: 'g-work', name: 'Work', sortOrder: 0, createdAt: '2026-06-01T09:00:00.000Z' },
103
- ];
104
- list.conversations = [
105
- {
106
- id: 'c-1', title: 'Q2 launch plan', groupId: 'g-work',
107
- scope: { type: 'collection' }, messageCount: 12,
108
- lastMessageAt: '2026-06-09T14:20:00.000Z', updatedAt: '2026-06-09T14:20:00.000Z',
109
- },
110
- ];
111
- list.activeId = 'c-1';
112
-
113
- // events are CustomEvents on the element (they do not bubble)
114
- list.addEventListener('kai-conversation-select', (e) => console.log('opened:', e.detail.id));
115
- list.addEventListener('kai-new-chat', () => console.log('new chat'));
116
- list.addEventListener('kai-toggle-sidebar', () => console.log('toggle sidebar'));
117
- </script>`;
118
-
119
- const SOLID_SNIPPET = `import '@kitn.ai/ui/elements'; // registers the custom elements
120
- import { onMount } from 'solid-js';
121
- import type { ConversationGroup, ConversationSummary } from '@kitn.ai/ui';
122
-
123
- function Sidebar() {
124
- let el: HTMLElement & {
125
- groups?: ConversationGroup[];
126
- conversations?: ConversationSummary[];
127
- activeId?: string;
128
- };
129
- const groups: ConversationGroup[] = [
130
- { id: 'g-work', name: 'Work', sortOrder: 0, createdAt: '2026-06-01T09:00:00.000Z' },
131
- ];
132
- const conversations: ConversationSummary[] = [
133
- {
134
- id: 'c-1', title: 'Q2 launch plan', groupId: 'g-work',
135
- scope: { type: 'collection' }, messageCount: 12,
136
- lastMessageAt: '2026-06-09T14:20:00.000Z', updatedAt: '2026-06-09T14:20:00.000Z',
137
- },
138
- ];
139
- onMount(() => {
140
- el.groups = groups;
141
- el.conversations = conversations;
142
- el.activeId = 'c-1';
143
- });
144
- return (
145
- <kai-conversations
146
- ref={el}
147
- style={{ display: 'block', width: '300px', height: '100vh' }}
148
- on:kai-conversation-select={(e) => console.log('opened:', e.detail.id)}
149
- on:kai-new-chat={() => console.log('new chat')}
150
- on:kai-toggle-sidebar={() => console.log('toggle sidebar')}
151
- />
152
- );
153
- }`;
154
-
155
- const meta = {
156
- title: 'Components/Conversations',
157
- tags: ['autodocs'],
158
- argTypes: argTypesFor('kai-conversations'),
159
- parameters: {
160
- layout: 'fullscreen',
161
- docs: {
162
- description: specDescription('kai-conversations', [
163
- '`<kai-conversations>` is the framework-agnostic **web component** version of the chat sidebar — a searchable, grouped list of conversations with a "new chat" button, isolated in **Shadow DOM** so the host page\'s CSS can\'t leak in and the kit\'s styles can\'t leak out. SolidJS is bundled in, so the host needs nothing.',
164
- '**When to use:** adding a conversation switcher to a non-Solid app (React, Vue, Svelte, plain HTML), or anywhere you want zero style conflicts. If you *are* in SolidJS and want fine-grained control, compose the `ConversationList` primitive instead.',
165
- '**How to use — data-driven:** register once with `import \'@kitn.ai/ui/elements\'`, then set rich data as JS **properties** (`el.groups = [...]`, `el.conversations = [...]`, `el.activeId = \'c-1\'`) and listen for **CustomEvents** (`kai-conversation-select`, `kai-new-chat`, `kai-toggle-sidebar`) directly on the element.',
166
- '**How to use — declarative:** alternatively, compose `<kai-conversation>` child elements directly in markup — each child carries its `id` as an attribute and its title as text content (`<kai-conversation id="c-1">Q2 plan</kai-conversation>`). No JS property wiring needed; the element reads them on mount and re-reads on DOM changes via MutationObserver. Events fire identically to the data-driven path.',
167
- '**Anatomy:** **header** (collapse/sidebar toggle button + "New chat" button) → **group headers** (one per `ConversationGroup`, labelled by `group.name`) → **conversation rows** (`<kai-conversation>` items or JS-property rows; active row is highlighted; each row is a button firing `kai-conversation-select`). Declarative `<kai-conversation id="…">title</kai-conversation>` children are invisible data carriers (no shadow slot) merged with the `conversations` property list.',
168
- '**Placement:** as a fixed-width side panel next to the chat surface. Give it an explicit width and height (e.g. `width: 300px; height: 100vh`).',
169
- 'See the **Code** tab below for the HTML usage; the *SolidJS* story shows the same element inside a Solid component.',
170
- ]),
171
- },
172
- },
173
- } satisfies Meta;
174
-
175
- export default meta;
176
- type Story = StoryObj;
177
-
178
- /** The element used the plain-HTML / any-framework way. */
179
- export const Default: Story = {
180
- args: {
181
- activeId: 'c-1',
182
- },
183
- render: (args: Record<string, unknown>) => <ConversationListElement args={args} />,
184
- parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
185
- };
186
-
187
- /** The same element used inside a SolidJS component (properties via `ref`, events via `on:`). */
188
- export const InSolidJS: Story = {
189
- name: 'In SolidJS',
190
- render: () => <ConversationListElement />,
191
- parameters: { docs: { source: { code: SOLID_SNIPPET, language: 'tsx' } } },
192
- };
193
-
194
- const DECLARATIVE_HTML_SNIPPET = `<!-- Works in any framework or plain HTML — no JS property wiring needed -->
195
- <kai-conversations id="list" style="display:block; width:300px; height:560px;">
196
- <kai-conversation id="c-1">Q2 launch plan</kai-conversation>
197
- <kai-conversation id="c-2">API migration notes</kai-conversation>
198
- <kai-conversation id="c-3">Weekend trip ideas</kai-conversation>
199
- </kai-conversations>
200
-
201
- <script type="module">
202
- import '@kitn.ai/ui/elements'; // registers the custom elements
203
-
204
- // Events fire exactly the same as the data-driven approach.
205
- document.getElementById('list')
206
- .addEventListener('kai-conversation-select', (e) => console.log('opened:', e.detail.id));
207
- </script>`;
208
-
209
- /** Declarative conversations — \`<kai-conversation>\` light-DOM children instead of
210
- * a \`conversations\` property. Each child carries its \`id\` as an attribute and
211
- * its title as text content. Great for plain HTML or server-rendered markup
212
- * where JS property wiring is inconvenient. */
213
- export const DeclarativeConversations: Story = {
214
- name: 'Declarative Conversations (kai-conversation)',
215
- render: () => {
216
- let el: HTMLElement | undefined;
217
- onMount(() => {
218
- if (!el) return;
219
- el.addEventListener('kai-conversation-select', (e: Event) => {
220
- console.log('selected:', (e as CustomEvent<{ id: string }>).detail.id);
221
- });
222
- });
223
- return (
224
- <kai-conversations
225
- ref={(e) => (el = e as HTMLElement)}
226
- style={{ display: 'block', width: '300px', height: '560px' }}
227
- >
228
- <kai-conversation id="c-1">Q2 launch plan</kai-conversation>
229
- <kai-conversation id="c-2">API migration notes</kai-conversation>
230
- <kai-conversation id="c-3">Weekend trip ideas</kai-conversation>
231
- </kai-conversations>
232
- );
233
- },
234
- parameters: {
235
- docs: {
236
- source: {
237
- code: DECLARATIVE_HTML_SNIPPET,
238
- language: 'html',
239
- },
240
- },
241
- },
242
- };
243
-