@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,331 +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 { AttachmentData } from '../components/attachments';
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-prompt-input': JSX.HTMLAttributes<HTMLElement>;
13
- 'kai-action': JSX.HTMLAttributes<HTMLElement> & { icon?: string; tooltip?: string };
14
- 'kai-slash-command': JSX.HTMLAttributes<HTMLElement> & { command?: string; description?: string; category?: string };
15
- }
16
- }
17
- }
18
-
19
- const sampleSuggestions: string[] = [
20
- 'Summarize this thread',
21
- 'Draft a reply',
22
- 'Explain like I am five',
23
- ];
24
-
25
- function imgData(fill: string, glyph: string) {
26
- const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="96" height="96"><rect width="96" height="96" rx="12" fill="${fill}"/><text x="48" y="60" font-size="42" text-anchor="middle" fill="white">${glyph}</text></svg>`;
27
- return 'data:image/svg+xml;utf8,' + encodeURIComponent(svg);
28
- }
29
-
30
- const sampleAttachments: AttachmentData[] = [
31
- { id: 'a1', type: 'file', filename: 'architecture.png', mediaType: 'image/png', url: imgData('#7c3aed', '◆') },
32
- { id: 'a2', type: 'file', filename: 'spec.pdf', mediaType: 'application/pdf' },
33
- ];
34
-
35
- interface PromptInputEl extends HTMLElement {
36
- value?: string;
37
- placeholder?: string;
38
- disabled?: boolean;
39
- loading?: boolean;
40
- suggestions?: string[];
41
- search?: boolean;
42
- voice?: boolean;
43
- attachments?: AttachmentData[];
44
- }
45
-
46
- /** Live demo of the actual `<kai-prompt-input>` custom element (Shadow DOM and all). */
47
- function PromptInputElement(props: { search?: boolean; voice?: boolean; attachments?: AttachmentData[]; args?: Record<string, unknown> }) {
48
- let el: PromptInputEl | undefined;
49
- onMount(() => {
50
- if (!el) return;
51
- // Default fixed data
52
- el.placeholder = 'Ask anything...';
53
- el.suggestions = sampleSuggestions;
54
- if (props.search) el.setAttribute('search', '');
55
- if (props.voice) el.setAttribute('voice', '');
56
- if (props.attachments) el.attachments = props.attachments;
57
- // Scalar args from Controls
58
- const args = props.args;
59
- if (args) {
60
- const scalarNames = [
61
- 'value', 'placeholder', 'disabled', 'loading', 'suggestionMode',
62
- 'slashCompact', 'search', 'voice',
63
- ];
64
- for (const name of scalarNames) {
65
- if (name in args) (el as unknown as Record<string, unknown>)[name] = args[name];
66
- }
67
- }
68
- el.addEventListener('kai-search', () => console.log('search clicked'));
69
- el.addEventListener('kai-voice', () => console.log('voice clicked'));
70
- });
71
- return (
72
- <kai-prompt-input
73
- ref={(e) => (el = e as PromptInputEl)}
74
- style={{ display: 'block', width: '100%', padding: '16px' }}
75
- />
76
- );
77
- }
78
-
79
- const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
80
- <kai-prompt-input id="input" style="display:block; width:100%;"></kai-prompt-input>
81
-
82
- <script type="module">
83
- import '@kitn.ai/ui/elements'; // registers the custom elements
84
-
85
- const input = document.getElementById('input');
86
- input.placeholder = 'Ask anything...';
87
- input.suggestions = ['Summarize this thread', 'Draft a reply'];
88
- // input.loading = true; // shows the busy state while a response streams
89
- // input.disabled = true; // blocks typing and submit
90
-
91
- // events are CustomEvents on the element (they do not bubble)
92
- input.addEventListener('kai-submit', (e) => console.log('send:', e.detail.value));
93
- input.addEventListener('kai-value-change', (e) => console.log('typing:', e.detail.value));
94
- input.addEventListener('kai-suggestion-click', (e) => console.log('picked:', e.detail.value));
95
- </script>`;
96
-
97
- const SOLID_SNIPPET = `import '@kitn.ai/ui/elements'; // registers the custom elements
98
- import { onMount } from 'solid-js';
99
-
100
- function Composer() {
101
- let el: HTMLElement & {
102
- value?: string;
103
- placeholder?: string;
104
- disabled?: boolean;
105
- loading?: boolean;
106
- suggestions?: string[];
107
- };
108
- onMount(() => {
109
- el.placeholder = 'Ask anything...';
110
- el.suggestions = ['Summarize this thread', 'Draft a reply'];
111
- });
112
- return (
113
- <kai-prompt-input
114
- ref={el}
115
- style={{ display: 'block', width: '100%' }}
116
- on:kai-submit={(e) => console.log('send:', e.detail.value)}
117
- on:kai-value-change={(e) => console.log('typing:', e.detail.value)}
118
- on:kai-suggestion-click={(e) => console.log('picked:', e.detail.value)}
119
- />
120
- );
121
- }`;
122
-
123
- const meta = {
124
- title: 'Components/PromptInput',
125
- tags: ['autodocs'],
126
- argTypes: argTypesFor('kai-prompt-input'),
127
- parameters: {
128
- layout: 'fullscreen',
129
- docs: {
130
- description: specDescription('kai-prompt-input', [
131
- '`<kai-prompt-input>` is the framework-agnostic **web component** version of the chat composer — an auto-resizing textarea with a send button and optional suggestion chips, 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.',
132
- '**When to use:** adding a message composer 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 `PromptInput` primitives instead.',
133
- '**How to use:** register once with `import \'@kitn.ai/ui/elements\'`, configure it with JS **properties** (`placeholder`, `value`, `disabled`, `loading`, `suggestions`, `attachments`) and flag attributes (`search`, `voice` to show the Globe/Mic toolbar buttons), and listen for **CustomEvents** (`kai-submit`, `kai-value-change`, `kai-suggestion-click`, `kai-search`, `kai-voice`) directly on the element. Leave `value` unset to let the element manage its own input state; seed `attachments` to pre-populate staged files. **Custom toolbar buttons:** place `<kai-action id icon tooltip>` elements as children — they are invisible data carriers (Shadow DOM hides them) that the element reads and renders as extra ghost icon buttons in the left toolbar. Each click fires a `kai-toolbar-action` CustomEvent with `detail.action` equal to the action id (the same `<kai-action>` descriptor element that `<kai-message>` uses — composition symmetry).',
134
- '**Slash commands (declarative):** place `<kai-slash-command command="id" description="…">Label</kai-slash-command>` elements as children — invisible data carriers merged with the `slashCommands` JS property. Typing `/` opens the palette with the combined list; selecting an item fires `kai-slash-select` with `detail.command`. Prop items appear first; declarative children are appended.',
135
- '**Placement:** pinned to the bottom of a chat surface, full width. Set `loading` while a response streams to show the busy state, and `disabled` to block input entirely.',
136
- 'See the **Code** tab below for the HTML usage; the *SolidJS* story shows the same element inside a Solid component.',
137
- ]),
138
- },
139
- },
140
- } satisfies Meta;
141
-
142
- export default meta;
143
- type Story = StoryObj;
144
-
145
- /** The element used the plain-HTML / any-framework way. */
146
- export const Default: Story = {
147
- args: {
148
- placeholder: 'Send a message...',
149
- disabled: false,
150
- loading: false,
151
- suggestionMode: 'submit',
152
- slashCompact: false,
153
- search: false,
154
- voice: false,
155
- },
156
- render: (args: Record<string, unknown>) => <PromptInputElement args={args} />,
157
- parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
158
- };
159
-
160
- /** The same element used inside a SolidJS component (properties via `ref`, events via `on:`). */
161
- export const InSolidJS: Story = {
162
- name: 'In SolidJS',
163
- render: () => <PromptInputElement />,
164
- parameters: { docs: { source: { code: SOLID_SNIPPET, language: 'tsx' } } },
165
- };
166
-
167
- const TOOLBAR_SNIPPET = `<!-- show the Search (Globe) + Voice (Mic) toolbar buttons -->
168
- <kai-prompt-input id="input" search voice></kai-prompt-input>
169
-
170
- <script type="module">
171
- import '@kitn.ai/ui/elements';
172
- const input = document.getElementById('input');
173
- input.addEventListener('kai-search', () => console.log('search clicked'));
174
- input.addEventListener('kai-voice', () => console.log('voice clicked'));
175
- </script>`;
176
-
177
- /** With the **microphone** (and search) toolbar buttons enabled via the `voice`
178
- * and `search` flags. Clicking them fires `kai-voice` / `kai-search` CustomEvents. */
179
- export const WithVoiceAndSearch: Story = {
180
- name: 'With Voice & Search',
181
- render: () => <PromptInputElement search voice />,
182
- parameters: { docs: { source: { code: TOOLBAR_SNIPPET, language: 'html' } } },
183
- };
184
-
185
- const ATTACHMENTS_SNIPPET = `<!-- seed staged attachments without an upload -->
186
- <kai-prompt-input id="input" voice></kai-prompt-input>
187
-
188
- <script type="module">
189
- import '@kitn.ai/ui/elements';
190
- const input = document.getElementById('input');
191
- input.attachments = [
192
- { id: 'a1', type: 'file', filename: 'architecture.png',
193
- mediaType: 'image/png', url: 'data:image/svg+xml;utf8,...' },
194
- { id: 'a2', type: 'file', filename: 'spec.pdf', mediaType: 'application/pdf' },
195
- ];
196
- </script>`;
197
-
198
- /** Pre-populated with a couple of **attachments** (an image + a file) via the
199
- * `attachments` property, with the mic shown too. The paperclip still adds
200
- * more, and each chip can be removed. */
201
- export const WithAttachments: Story = {
202
- name: 'With Attachments',
203
- render: () => <PromptInputElement voice attachments={sampleAttachments} />,
204
- parameters: { docs: { source: { code: ATTACHMENTS_SNIPPET, language: 'html' } } },
205
- };
206
-
207
- const CUSTOM_TOOLBAR_SNIPPET = `<kai-prompt-input id="input" voice></kai-prompt-input>
208
-
209
- <script type="module">
210
- import '@kitn.ai/ui/elements';
211
-
212
- const input = document.getElementById('input');
213
-
214
- // Inject <kai-action> children as toolbar buttons (declarative composition).
215
- ['attach', 'translate', 'bookmark'].forEach((id, i) => {
216
- const el = document.createElement('kai-action');
217
- el.id = id;
218
- el.setAttribute('icon', ['paperclip', 'flag', 'bookmark'][i]);
219
- el.setAttribute('tooltip', ['Attach', 'Translate', 'Bookmark'][i]);
220
- input.appendChild(el);
221
- });
222
-
223
- input.addEventListener('kai-toolbar-action', (e) => {
224
- console.log('toolbar action:', e.detail.action);
225
- });
226
- input.addEventListener('kai-submit', (e) => console.log('submit:', e.detail.value));
227
- </script>`;
228
-
229
- const SLASH_COMMAND_SNIPPET = `<kai-prompt-input id="input" style="display:block; width:100%;"></kai-prompt-input>
230
-
231
- <script type="module">
232
- import '@kitn.ai/ui/elements';
233
-
234
- const input = document.getElementById('input');
235
-
236
- // Inject <kai-slash-command> children — invisible data carriers read via
237
- // querySelectorAll + MutationObserver, merged with any slashCommands property.
238
- [
239
- { command: 'summarize', description: 'Summarize the thread' },
240
- { command: 'translate', description: 'Translate to English' },
241
- { command: 'explain', description: "Explain like I'm five" },
242
- ].forEach(({ command, description }) => {
243
- const el = document.createElement('kai-slash-command');
244
- el.setAttribute('command', command);
245
- el.setAttribute('description', description);
246
- el.textContent = command; // becomes the label
247
- input.appendChild(el);
248
- });
249
-
250
- input.addEventListener('kai-slash-select', (e) => {
251
- console.log('slash selected:', e.detail.command);
252
- });
253
- </script>`;
254
-
255
- /** Composition: place **`<kai-action>`** children inside `<kai-prompt-input>` to add
256
- * custom ghost icon buttons in the toolbar. Each click fires a `kai-toolbar-action` event
257
- * with `detail.action` equal to the action id — the same `<kai-action>` descriptor
258
- * element that `<kai-message>` uses for its action bar (composition symmetry). */
259
- export const WithCustomToolbarActions: Story = {
260
- name: 'Custom Toolbar Actions (kai-action)',
261
- render: () => {
262
- let el: HTMLElement | undefined;
263
- onMount(() => {
264
- if (!el) return;
265
- el.setAttribute('placeholder', 'Ask anything...');
266
- el.addEventListener('kai-toolbar-action', (e: Event) => {
267
- console.log('toolbar action:', (e as CustomEvent<{ action: string }>).detail.action);
268
- });
269
- });
270
- return (
271
- <div style={{ padding: '16px', width: '100%' }}>
272
- <kai-prompt-input
273
- ref={(e: HTMLElement) => (el = e)}
274
- style={{ display: 'block', width: '100%' }}
275
- >
276
- {/* <kai-action> children are invisible data carriers — Shadow DOM hides them.
277
- The element reads them via querySelectorAll + MutationObserver and renders
278
- a ghost icon button per entry in the left toolbar. Clicking fires kai-action. */}
279
- <kai-action id="attach" icon="paperclip" tooltip="Attach" />
280
- <kai-action id="translate" icon="flag" tooltip="Translate" />
281
- <kai-action id="bookmark" icon="bookmark" tooltip="Bookmark" />
282
- </kai-prompt-input>
283
- <p style={{ 'margin-top': '8px', 'font-size': '12px', color: 'var(--color-muted-foreground)' }}>
284
- Open the browser console to see <code>kai-action</code> events when you click the extra toolbar buttons.
285
- </p>
286
- </div>
287
- );
288
- },
289
- parameters: { docs: { source: { code: CUSTOM_TOOLBAR_SNIPPET, language: 'html' } } },
290
- };
291
-
292
- /** Composition: place **`<kai-slash-command>`** children inside `<kai-prompt-input>`
293
- * to declare slash commands without setting the `slashCommands` JS property.
294
- * Type `/` in the input to open the palette. Each `<kai-slash-command>` child maps:
295
- * `command` attr → id, textContent → label, `description` attr → description.
296
- * Selection fires `kai-slash-select` with `detail.command`.
297
- * Prop (`slashCommands`) and declarative children are merged — prop items first. */
298
- export const DeclarativeSlashCommands: Story = {
299
- name: 'Declarative Slash Commands (kai-slash-command)',
300
- render: () => {
301
- let el: HTMLElement | undefined;
302
- onMount(() => {
303
- if (!el) return;
304
- el.setAttribute('placeholder', 'Type / to open the command palette…');
305
- el.addEventListener('kai-slash-select', (e: Event) => {
306
- console.log('slash selected:', (e as CustomEvent<{ command: unknown }>).detail.command);
307
- });
308
- });
309
- return (
310
- <div style={{ padding: '16px', width: '100%' }}>
311
- <kai-prompt-input
312
- ref={(e: HTMLElement) => (el = e)}
313
- style={{ display: 'block', width: '100%' }}
314
- >
315
- {/* <kai-slash-command> children are invisible data carriers — Shadow DOM hides them.
316
- The element reads them via querySelectorAll + MutationObserver.
317
- command attr → id, textContent → label, description attr → description. */}
318
- <kai-slash-command command="summarize" description="Summarize the thread">summarize</kai-slash-command>
319
- <kai-slash-command command="translate" description="Translate to English">translate</kai-slash-command>
320
- <kai-slash-command command="explain" description="Explain like I'm five">explain</kai-slash-command>
321
- </kai-prompt-input>
322
- <p style={{ 'margin-top': '8px', 'font-size': '12px', color: 'var(--color-muted-foreground)' }}>
323
- Type <code>/</code> in the input to open the command palette. Open the browser
324
- console to see <code>kai-slash-select</code> events on selection.
325
- </p>
326
- </div>
327
- );
328
- },
329
- parameters: { docs: { source: { code: SLASH_COMMAND_SNIPPET, language: 'html' } } },
330
- };
331
-
@@ -1,164 +0,0 @@
1
- /**
2
- * Unit tests for the declarative `<kai-suggestion>` light-DOM API of
3
- * `<kai-suggestions>`.
4
- *
5
- * Strategy: the `defineWebComponent` call registers a real Shadow-DOM custom
6
- * element which requires a full browser environment (Constructable Stylesheets,
7
- * shadow roots, etc.) and is therefore not suitable for jsdom unit tests.
8
- * Instead we:
9
- * 1. Test the exported `parseSuggestionNode` helper in isolation — it has no
10
- * DOM dependencies beyond `Element`, which jsdom provides perfectly.
11
- * 2. Test that the merged list of prop + slotted items renders chip buttons
12
- * and fires click handlers correctly via `PromptSuggestion` directly,
13
- * mirroring the pattern used in `message-action-bar.test.tsx`.
14
- */
15
- import { describe, it, expect, vi, afterEach } from 'vitest';
16
- import '@testing-library/jest-dom/vitest';
17
- import { render, cleanup, fireEvent } from '@solidjs/testing-library';
18
- import { For } from 'solid-js';
19
- import { parseSuggestionNode } from './prompt-suggestions';
20
- import { PromptSuggestion } from '../components/prompt-suggestion';
21
-
22
- afterEach(cleanup);
23
-
24
- // ---------------------------------------------------------------------------
25
- // parseSuggestionNode — pure helper
26
- // ---------------------------------------------------------------------------
27
-
28
- describe('parseSuggestionNode', () => {
29
- function makeNode(textContent: string, value?: string): Element {
30
- const el = document.createElement('kai-suggestion');
31
- el.textContent = textContent;
32
- if (value !== undefined) el.setAttribute('value', value);
33
- return el;
34
- }
35
-
36
- it('uses textContent as label', () => {
37
- const item = parseSuggestionNode(makeNode('Use Vue'));
38
- expect(item).toMatchObject({ label: 'Use Vue' });
39
- });
40
-
41
- it('uses value attribute as value when present', () => {
42
- const item = parseSuggestionNode(makeNode('Use Vue', 'vue'));
43
- expect(item).toMatchObject({ label: 'Use Vue', value: 'vue' });
44
- });
45
-
46
- it('falls back to textContent as value when value attribute is absent', () => {
47
- const item = parseSuggestionNode(makeNode('Use Vue'));
48
- expect(item).toMatchObject({ label: 'Use Vue', value: 'Use Vue' });
49
- });
50
-
51
- it('trims leading/trailing whitespace from textContent', () => {
52
- const item = parseSuggestionNode(makeNode(' Explain the architecture '));
53
- expect(item).toMatchObject({ label: 'Explain the architecture' });
54
- });
55
-
56
- it('handles empty textContent with a value attribute', () => {
57
- const item = parseSuggestionNode(makeNode('', 'vue'));
58
- expect(item).toMatchObject({ label: '', value: 'vue' });
59
- });
60
- });
61
-
62
- // ---------------------------------------------------------------------------
63
- // Merge + render: prop suggestions + slotted suggestions combine correctly
64
- // ---------------------------------------------------------------------------
65
-
66
- type Item = string | { label: string; value?: string };
67
-
68
- const labelOf = (s: Item) => (typeof s === 'string' ? s : s.label);
69
- const valueOf = (s: Item) => (typeof s === 'string' ? s : s.value ?? s.label);
70
-
71
- /**
72
- * Minimal test harness that renders a list of `Item`s as `PromptSuggestion`
73
- * chips and records which value was clicked — mirrors the render path in
74
- * `prompt-suggestions.tsx`.
75
- */
76
- function SuggestionList(props: { items: Item[]; onSelect: (value: string) => void }) {
77
- return (
78
- <div>
79
- <For each={props.items}>
80
- {(s) => (
81
- <PromptSuggestion onClick={() => props.onSelect(valueOf(s))}>
82
- {labelOf(s)}
83
- </PromptSuggestion>
84
- )}
85
- </For>
86
- </div>
87
- );
88
- }
89
-
90
- describe('suggestion chip rendering and click events', () => {
91
- it('renders one chip per item', () => {
92
- const { getByText } = render(() => (
93
- <SuggestionList
94
- items={['Explain the architecture', 'Show me a code example']}
95
- onSelect={() => {}}
96
- />
97
- ));
98
- expect(getByText('Explain the architecture')).toBeInTheDocument();
99
- expect(getByText('Show me a code example')).toBeInTheDocument();
100
- });
101
-
102
- it('fires onSelect with the string value when a string item is clicked', () => {
103
- const onSelect = vi.fn();
104
- const { getByText } = render(() => (
105
- <SuggestionList items={['Use Vue']} onSelect={onSelect} />
106
- ));
107
- fireEvent.click(getByText('Use Vue'));
108
- expect(onSelect).toHaveBeenCalledWith('Use Vue');
109
- });
110
-
111
- it('fires onSelect with item.value for an object item with an explicit value', () => {
112
- const onSelect = vi.fn();
113
- const { getByText } = render(() => (
114
- <SuggestionList
115
- items={[{ label: 'Use Vue', value: 'vue' }]}
116
- onSelect={onSelect}
117
- />
118
- ));
119
- fireEvent.click(getByText('Use Vue'));
120
- expect(onSelect).toHaveBeenCalledWith('vue');
121
- });
122
-
123
- it('falls back to label as value for an object item without explicit value', () => {
124
- const onSelect = vi.fn();
125
- const { getByText } = render(() => (
126
- <SuggestionList
127
- items={[{ label: 'Use Vue' }]}
128
- onSelect={onSelect}
129
- />
130
- ));
131
- fireEvent.click(getByText('Use Vue'));
132
- expect(onSelect).toHaveBeenCalledWith('Use Vue');
133
- });
134
-
135
- it('renders prop items before declarative (slotted) items', () => {
136
- // Simulate the merge: prop first, slotted second.
137
- const propItems: Item[] = [{ label: 'Prop item', value: 'prop' }];
138
- const slottedItems: Item[] = [{ label: 'Slotted item', value: 'slotted' }];
139
- const merged = [...propItems, ...slottedItems];
140
-
141
- const { getAllByRole } = render(() => (
142
- <SuggestionList items={merged} onSelect={() => {}} />
143
- ));
144
- const buttons = getAllByRole('button');
145
- expect(buttons).toHaveLength(2);
146
- expect(buttons[0]).toHaveTextContent('Prop item');
147
- expect(buttons[1]).toHaveTextContent('Slotted item');
148
- });
149
-
150
- it('parseSuggestionNode produces items that render and fire the correct value', () => {
151
- // End-to-end: parse a DOM node → render it → click → verify event value.
152
- const onSelect = vi.fn();
153
- const el = document.createElement('kai-suggestion');
154
- el.textContent = 'Use Vue';
155
- el.setAttribute('value', 'vue');
156
-
157
- const parsed = parseSuggestionNode(el);
158
- const { getByText } = render(() => (
159
- <SuggestionList items={[parsed]} onSelect={onSelect} />
160
- ));
161
- fireEvent.click(getByText('Use Vue'));
162
- expect(onSelect).toHaveBeenCalledWith('vue');
163
- });
164
- });