@kitn.ai/ui 0.15.0 → 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 (177) hide show
  1. package/dist/kitn-chat.es.js +1 -1
  2. package/package.json +6 -1
  3. package/src/elements/compiled.css +1 -1
  4. package/src/components/artifact.stories.tsx +0 -138
  5. package/src/components/attachments.stories.tsx +0 -303
  6. package/src/components/attachments.test.tsx +0 -64
  7. package/src/components/chain-of-thought.stories.tsx +0 -211
  8. package/src/components/chat-container.stories.tsx +0 -187
  9. package/src/components/chat-thread.test.tsx +0 -58
  10. package/src/components/checkpoint.stories.tsx +0 -102
  11. package/src/components/code-block.stories.tsx +0 -150
  12. package/src/components/confirm-card.stories.tsx +0 -74
  13. package/src/components/context.stories.tsx +0 -229
  14. package/src/components/context.test.tsx +0 -133
  15. package/src/components/conversation-item.stories.tsx +0 -125
  16. package/src/components/conversation-list.stories.tsx +0 -133
  17. package/src/components/default-input.test.tsx +0 -111
  18. package/src/components/empty.stories.tsx +0 -434
  19. package/src/components/feedback-bar.stories.tsx +0 -138
  20. package/src/components/feedback-bar.test.tsx +0 -103
  21. package/src/components/file-tree.stories.tsx +0 -73
  22. package/src/components/file-upload.stories.tsx +0 -156
  23. package/src/components/image.stories.tsx +0 -89
  24. package/src/components/loader.stories.tsx +0 -181
  25. package/src/components/markdown.stories.tsx +0 -180
  26. package/src/components/message-action-bar.test.tsx +0 -128
  27. package/src/components/message-narrow.stories.tsx +0 -329
  28. package/src/components/message-skills.stories.tsx +0 -211
  29. package/src/components/message.stories.tsx +0 -281
  30. package/src/components/model-switcher.stories.tsx +0 -123
  31. package/src/components/model-switcher.test.tsx +0 -65
  32. package/src/components/prompt-input.stories.tsx +0 -222
  33. package/src/components/prompt-suggestion.stories.tsx +0 -142
  34. package/src/components/reasoning.stories.tsx +0 -140
  35. package/src/components/resizable.test.tsx +0 -226
  36. package/src/components/scroll-button.stories.tsx +0 -100
  37. package/src/components/slash-command.stories.tsx +0 -163
  38. package/src/components/source-list.test.tsx +0 -152
  39. package/src/components/source.stories.tsx +0 -124
  40. package/src/components/tasks-card.stories.tsx +0 -78
  41. package/src/components/text-shimmer.stories.tsx +0 -87
  42. package/src/components/thinking-bar.stories.tsx +0 -87
  43. package/src/components/tool.stories.tsx +0 -153
  44. package/src/components/voice-input.stories.tsx +0 -83
  45. package/src/elements/artifact.stories.tsx +0 -506
  46. package/src/elements/attachments.stories.tsx +0 -190
  47. package/src/elements/card.stories.tsx +0 -113
  48. package/src/elements/cards.stories.tsx +0 -59
  49. package/src/elements/catalog.stories.tsx +0 -491
  50. package/src/elements/chain-of-thought.declarative.test.tsx +0 -153
  51. package/src/elements/chain-of-thought.stories.tsx +0 -113
  52. package/src/elements/chat-scope-picker.stories.tsx +0 -73
  53. package/src/elements/chat-workspace.stories.tsx +0 -288
  54. package/src/elements/chat.stories.tsx +0 -151
  55. package/src/elements/checkpoint.stories.tsx +0 -72
  56. package/src/elements/choice.stories.tsx +0 -240
  57. package/src/elements/code-block.stories.tsx +0 -83
  58. package/src/elements/composed-shell.stories.tsx +0 -316
  59. package/src/elements/confirm-card.stories.tsx +0 -227
  60. package/src/elements/context-meter.stories.tsx +0 -151
  61. package/src/elements/conversation-list.declarative.test.tsx +0 -137
  62. package/src/elements/conversation-list.stories.tsx +0 -243
  63. package/src/elements/embed.stories.tsx +0 -213
  64. package/src/elements/empty.stories.tsx +0 -111
  65. package/src/elements/feedback-bar.stories.tsx +0 -114
  66. package/src/elements/file-tree.stories.tsx +0 -134
  67. package/src/elements/file-upload.stories.tsx +0 -82
  68. package/src/elements/form.stories.tsx +0 -248
  69. package/src/elements/image.stories.tsx +0 -71
  70. package/src/elements/link-preview.stories.tsx +0 -209
  71. package/src/elements/loader.stories.tsx +0 -88
  72. package/src/elements/markdown.stories.tsx +0 -76
  73. package/src/elements/message-skills.declarative.test.tsx +0 -104
  74. package/src/elements/message-skills.stories.tsx +0 -114
  75. package/src/elements/message.stories.tsx +0 -218
  76. package/src/elements/model-switcher.declarative.test.tsx +0 -130
  77. package/src/elements/model-switcher.stories.tsx +0 -198
  78. package/src/elements/popover.stories.tsx +0 -80
  79. package/src/elements/prompt-input-slash-command.test.tsx +0 -128
  80. package/src/elements/prompt-input-stoppable.test.tsx +0 -88
  81. package/src/elements/prompt-input-toolbar-actions.test.tsx +0 -120
  82. package/src/elements/prompt-input.stories.tsx +0 -331
  83. package/src/elements/prompt-suggestions.declarative.test.tsx +0 -164
  84. package/src/elements/prompt-suggestions.stories.tsx +0 -213
  85. package/src/elements/reasoning.stories.tsx +0 -77
  86. package/src/elements/remote.stories.tsx +0 -314
  87. package/src/elements/resizable.stories.tsx +0 -426
  88. package/src/elements/response-stream.stories.tsx +0 -79
  89. package/src/elements/scroll-button.stories.tsx +0 -202
  90. package/src/elements/scroll-button.test.tsx +0 -148
  91. package/src/elements/source-list.stories.tsx +0 -143
  92. package/src/elements/source.stories.tsx +0 -88
  93. package/src/elements/switch.stories.tsx +0 -56
  94. package/src/elements/tasks.stories.tsx +0 -237
  95. package/src/elements/text-shimmer.stories.tsx +0 -64
  96. package/src/elements/thinking-bar.stories.tsx +0 -72
  97. package/src/elements/tool.stories.tsx +0 -89
  98. package/src/elements/voice-input.stories.tsx +0 -88
  99. package/src/primitives/controllable.test.ts +0 -47
  100. package/src/stories/chat-panel-layout.stories.tsx +0 -145
  101. package/src/stories/chat-scene.tsx +0 -571
  102. package/src/stories/checkpoint-restore.stories.tsx +0 -256
  103. package/src/stories/context-usage.stories.tsx +0 -212
  104. package/src/stories/conversation-with-reasoning.stories.tsx +0 -182
  105. package/src/stories/conversation-with-sources.stories.tsx +0 -471
  106. package/src/stories/docs/Accessibility.mdx +0 -119
  107. package/src/stories/docs/ChildElements.mdx +0 -269
  108. package/src/stories/docs/ForAIAgents.mdx +0 -162
  109. package/src/stories/docs/GettingStarted.mdx +0 -65
  110. package/src/stories/docs/Installation.mdx +0 -83
  111. package/src/stories/docs/Introduction.mdx +0 -50
  112. package/src/stories/docs/SolidJsAdvanced.mdx +0 -17
  113. package/src/stories/docs/Theming.mdx +0 -85
  114. package/src/stories/docs/element-controls.ts +0 -121
  115. package/src/stories/docs/frameworks/Angular.mdx +0 -245
  116. package/src/stories/docs/frameworks/Html.mdx +0 -227
  117. package/src/stories/docs/frameworks/Overview.mdx +0 -47
  118. package/src/stories/docs/frameworks/React.mdx +0 -227
  119. package/src/stories/docs/frameworks/Solid.mdx +0 -173
  120. package/src/stories/docs/frameworks/Svelte.mdx +0 -194
  121. package/src/stories/docs/frameworks/Vue.mdx +0 -238
  122. package/src/stories/docs/generative-ui-overview.mdx +0 -186
  123. package/src/stories/docs/recipes/SpeechToText.mdx +0 -7
  124. package/src/stories/docs/recipes/Streaming.mdx +0 -68
  125. package/src/stories/docs/recipes/TextToSpeech.mdx +0 -35
  126. package/src/stories/docs/theme-editor/canvas.tsx +0 -32
  127. package/src/stories/docs/theme-editor/inspector.tsx +0 -66
  128. package/src/stories/docs/theme-editor/presets.test.ts +0 -32
  129. package/src/stories/docs/theme-editor/presets.ts +0 -64
  130. package/src/stories/docs/theme-editor/theme-css.test.ts +0 -19
  131. package/src/stories/docs/theme-editor/theme-css.ts +0 -15
  132. package/src/stories/docs/theme-editor/theme-editor.tsx +0 -146
  133. package/src/stories/docs/theme-tokens.tsx +0 -174
  134. package/src/stories/examples/ChoosingComponents.mdx +0 -106
  135. package/src/stories/examples/sample-data.ts +0 -79
  136. package/src/stories/examples/usage/checkpoint-restore.ts +0 -156
  137. package/src/stories/examples/usage/context-usage.ts +0 -591
  138. package/src/stories/examples/usage/conversation-with-reasoning.ts +0 -224
  139. package/src/stories/examples/usage/conversation-with-sources.ts +0 -589
  140. package/src/stories/examples/usage/empty-state.ts +0 -144
  141. package/src/stories/examples/usage/full-chat-app.ts +0 -277
  142. package/src/stories/examples/usage/index.ts +0 -63
  143. package/src/stories/examples/usage/message-actions.ts +0 -704
  144. package/src/stories/examples/usage/pattern-centered-conversation.ts +0 -446
  145. package/src/stories/examples/usage/pattern-chat-panel-layout.ts +0 -442
  146. package/src/stories/examples/usage/pattern-docked-widget.ts +0 -479
  147. package/src/stories/examples/usage/prompt-input-variants.ts +0 -1356
  148. package/src/stories/examples/usage/streaming-response.ts +0 -687
  149. package/src/stories/examples/usage/types.ts +0 -33
  150. package/src/stories/full-chat.stories.tsx +0 -18
  151. package/src/stories/message-actions.stories.tsx +0 -230
  152. package/src/stories/pattern-centered-conversation.stories.tsx +0 -93
  153. package/src/stories/pattern-docked-widget.stories.tsx +0 -93
  154. package/src/stories/pattern-empty-state.stories.tsx +0 -76
  155. package/src/stories/prompt-input-variants.stories.tsx +0 -456
  156. package/src/stories/streaming-response.stories.tsx +0 -438
  157. package/src/stories/theme-editor.stories.tsx +0 -16
  158. package/src/stories/token-reference.stories.tsx +0 -18
  159. package/src/stories/typography.stories.tsx +0 -78
  160. package/src/ui/avatar.stories.tsx +0 -103
  161. package/src/ui/badge.stories.tsx +0 -86
  162. package/src/ui/button.stories.tsx +0 -145
  163. package/src/ui/collapsible.stories.tsx +0 -69
  164. package/src/ui/dropdown.stories.tsx +0 -59
  165. package/src/ui/hover-card.stories.tsx +0 -77
  166. package/src/ui/hover-card.test.tsx +0 -30
  167. package/src/ui/overlay.stories.tsx +0 -115
  168. package/src/ui/popover.stories.tsx +0 -81
  169. package/src/ui/popover.test.tsx +0 -99
  170. package/src/ui/resizable.stories.tsx +0 -236
  171. package/src/ui/scroll-area.stories.tsx +0 -50
  172. package/src/ui/separator.stories.tsx +0 -81
  173. package/src/ui/skeleton.stories.tsx +0 -337
  174. package/src/ui/switch.stories.tsx +0 -51
  175. package/src/ui/switch.test.tsx +0 -59
  176. package/src/ui/textarea.stories.tsx +0 -76
  177. package/src/ui/tooltip.stories.tsx +0 -74
@@ -1,198 +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 type { ModelOption } 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-model-switcher': JSX.HTMLAttributes<HTMLElement>;
13
- /** Light-DOM data carrier for declarative model options inside `<kai-model-switcher>`. */
14
- 'kai-model': JSX.HTMLAttributes<HTMLElement> & {
15
- id?: string;
16
- provider?: string;
17
- description?: string;
18
- group?: string;
19
- };
20
- }
21
- }
22
- }
23
-
24
- const models: ModelOption[] = [
25
- { id: 'opus', name: 'Claude Opus', provider: 'Anthropic' },
26
- { id: 'sonnet', name: 'Claude Sonnet', provider: 'Anthropic' },
27
- { id: 'haiku', name: 'Claude Haiku', provider: 'Anthropic' },
28
- ];
29
-
30
- /** Render `<kai-model-switcher>` with `models` set as a property; tracks selection. */
31
- function SwitcherElement(props: { models: ModelOption[]; current?: string }) {
32
- let el: (HTMLElement & { models?: ModelOption[]; currentModel?: string }) | undefined;
33
- onMount(() => {
34
- if (!el) return;
35
- el.models = props.models;
36
- el.currentModel = props.current ?? props.models[0]?.id;
37
- // reflect the selection back so the trigger label updates
38
- el.addEventListener('kai-model-change', (e) => {
39
- const ev = e as CustomEvent<{ modelId: string }>;
40
- el!.currentModel = ev.detail.modelId;
41
- });
42
- });
43
- return (
44
- <kai-model-switcher ref={(e) => (el = e as HTMLElement)} style={{ display: 'inline-block', padding: '40px' }} />
45
- );
46
- }
47
-
48
- const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
49
- <kai-model-switcher id="ms"></kai-model-switcher>
50
-
51
- <script type="module">
52
- import '@kitn.ai/ui/elements'; // registers the custom elements
53
-
54
- const ms = document.getElementById('ms');
55
- ms.models = [
56
- { id: 'opus', name: 'Claude Opus', provider: 'Anthropic' },
57
- { id: 'sonnet', name: 'Claude Sonnet', provider: 'Anthropic' },
58
- ];
59
- ms.currentModel = 'opus';
60
- ms.addEventListener('kai-model-change', (e) => { ms.currentModel = e.detail.modelId; });
61
- </script>`;
62
-
63
- const meta = {
64
- title: 'Components/ModelSwitcher',
65
- tags: ['autodocs'],
66
- argTypes: argTypesFor('kai-model-switcher'),
67
- parameters: {
68
- layout: 'fullscreen',
69
- docs: {
70
- description: specDescription('kai-model-switcher', [
71
- '`<kai-model-switcher>` is the framework-agnostic **web component** for picking the active model — a dropdown showing each model\'s name and provider — isolated in **Shadow DOM**. It mirrors the switcher inside `<kai-chat>` as a standalone, composable piece.',
72
- '**When to use:** building your own chat header and want the model picker on its own. In SolidJS, use the `ModelSwitcher` primitive.',
73
- '**Placement:** inline in the chat header or toolbar, typically to the left of the context meter; it is a compact `inline-block` dropdown trigger that fits naturally beside other header controls.',
74
- "**How to use — property API:** register once with `import '@kitn.ai/ui/elements'`, set the `models` **property** (each item: `{ id, name, provider? }`) and optionally `currentModel`, and listen for the `kai-model-change` **CustomEvent** (payload: `{ modelId }`). Note: like the underlying primitive, it only renders when more than one model is provided.",
75
- "**How to use — declarative API:** compose `<kai-model>` light-DOM children instead of (or in addition to) setting the `models` property. Each `<kai-model id=\"gpt-4o\" provider=\"OpenAI\">GPT-4o</kai-model>` carries `id` (required), `provider` (optional), and a text label as its content. Children are hidden data carriers — no JS property assignment needed. Prop `models` items render first; `<kai-model>` children follow.",
76
- 'See the **Code** tab for HTML usage.',
77
- ]),
78
- },
79
- },
80
- } satisfies Meta;
81
-
82
- export default meta;
83
- type Story = StoryObj;
84
-
85
- /** A three-model picker; selecting updates the trigger label. */
86
- export const Default: Story = {
87
- render: () => <SwitcherElement models={models} current="opus" />,
88
- parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
89
- };
90
-
91
- /** Raw data — the `models` array shape that `<kai-model-switcher>` consumes. */
92
- export const Data: Story = {
93
- name: 'Data',
94
- render: () => (
95
- <pre style={{ padding: '16px', 'font-size': '13px' }}>
96
- {JSON.stringify(
97
- [
98
- { id: 'opus', name: 'Claude Opus', provider: 'Anthropic' },
99
- { id: 'sonnet', name: 'Claude Sonnet', provider: 'Anthropic' },
100
- { id: 'gpt-4o', name: 'GPT-4o', provider: 'OpenAI' },
101
- ],
102
- null,
103
- 2,
104
- )}
105
- </pre>
106
- ),
107
- };
108
-
109
- const DECLARATIVE_HTML_SNIPPET = `<!-- Works in any framework or plain HTML — no JS property assignment needed -->
110
- <kai-model-switcher id="ms">
111
- <kai-model id="gpt-4o" provider="OpenAI">GPT-4o</kai-model>
112
- <kai-model id="gpt-4o-mini" provider="OpenAI">GPT-4o mini</kai-model>
113
- <kai-model id="claude-sonnet" provider="Anthropic">Claude Sonnet</kai-model>
114
- </kai-model-switcher>
115
-
116
- <script type="module">
117
- import '@kitn.ai/ui/elements'; // registers the custom elements
118
-
119
- document.getElementById('ms').addEventListener('kai-model-change', (e) => {
120
- console.log('selected model:', e.detail.modelId);
121
- });
122
- </script>`;
123
-
124
- /**
125
- * Declare each model option as a `<kai-model>` child element — no `models`
126
- * property or JS array wiring needed. The `id` attribute is the model identifier
127
- * emitted in `kai-model-change`; `provider` is optional; `textContent` is the
128
- * display label. Children are light-DOM data carriers hidden by the Shadow DOM.
129
- * Mix with the `models` prop: prop items render first, declarative children after.
130
- * Note: the switcher only renders when more than one model is provided.
131
- */
132
- export const DeclarativeModels: Story = {
133
- name: 'Declarative Models (kai-model)',
134
- render: () => {
135
- let el: HTMLElement | undefined;
136
- onMount(() => {
137
- if (!el) return;
138
- el.addEventListener('kai-model-change', (e) =>
139
- console.log('kai-model-change', (e as CustomEvent<{ modelId: string }>).detail.modelId),
140
- );
141
- });
142
- return (
143
- <kai-model-switcher
144
- ref={(e) => (el = e as HTMLElement)}
145
- style={{ display: 'inline-block', padding: '40px' }}
146
- >
147
- <kai-model id="gpt-4o" provider="OpenAI">GPT-4o</kai-model>
148
- <kai-model id="gpt-4o-mini" provider="OpenAI">GPT-4o mini</kai-model>
149
- <kai-model id="claude-sonnet" provider="Anthropic">Claude Sonnet</kai-model>
150
- </kai-model-switcher>
151
- );
152
- },
153
- parameters: {
154
- docs: {
155
- source: { code: DECLARATIVE_HTML_SNIPPET, language: 'html' },
156
- },
157
- },
158
- };
159
-
160
- const GROUPED_HTML_SNIPPET = `<kai-model-switcher id="ms">
161
- <kai-model id="gpt-5.5" description="Flagship model">GPT-5.5</kai-model>
162
- <kai-model id="gpt-4o" group="Legacy models">GPT-4o</kai-model>
163
- <kai-model id="gpt-4.1" group="Legacy models">GPT-4.1</kai-model>
164
- </kai-model-switcher>
165
-
166
- <script type="module">
167
- import '@kitn.ai/ui/elements';
168
- document.getElementById('ms').addEventListener('kai-model-change', (e) => {
169
- console.log('selected model:', e.detail.modelId);
170
- });
171
- </script>`;
172
-
173
- /**
174
- * Rich rows + a collapsible group via `<kai-model>` attributes: `description`
175
- * renders as the row subtitle, and children sharing a `group` collect under a
176
- * collapsible section — the ChatGPT-style "Legacy models" pattern.
177
- */
178
- export const GroupedModels: Story = {
179
- name: 'Grouped & Described (kai-model)',
180
- render: () => {
181
- let el: HTMLElement | undefined;
182
- onMount(() => {
183
- if (!el) return;
184
- el.addEventListener('kai-model-change', (e) =>
185
- console.log('kai-model-change', (e as CustomEvent<{ modelId: string }>).detail.modelId),
186
- );
187
- });
188
- return (
189
- <kai-model-switcher ref={(e) => (el = e as HTMLElement)} style={{ display: 'inline-block', padding: '40px' }}>
190
- <kai-model id="gpt-5.5" description="Flagship model">GPT-5.5</kai-model>
191
- <kai-model id="gpt-5.5-mini" description="Faster, lighter">GPT-5.5 mini</kai-model>
192
- <kai-model id="gpt-4o" group="Legacy models">GPT-4o</kai-model>
193
- <kai-model id="gpt-4.1" group="Legacy models">GPT-4.1</kai-model>
194
- </kai-model-switcher>
195
- );
196
- },
197
- parameters: { docs: { source: { code: GROUPED_HTML_SNIPPET, language: 'html' } } },
198
- };
@@ -1,80 +0,0 @@
1
- import type { Meta, StoryObj } from 'storybook-solidjs-vite';
2
- import { createSignal, onMount, Show, For } from 'solid-js';
3
- import './register'; // side effect: registers the custom elements
4
- import { argTypesFor, specDescription } from '../stories/docs/element-controls';
5
-
6
- declare module 'solid-js' {
7
- // eslint-disable-next-line @typescript-eslint/no-namespace
8
- namespace JSX {
9
- interface IntrinsicElements {
10
- 'kai-popover': JSX.HTMLAttributes<HTMLElement> & { placement?: string; gutter?: number | string; open?: boolean };
11
- }
12
- }
13
- }
14
-
15
- const HTML_SNIPPET = `<kai-popover placement="bottom-start">
16
- <button slot="trigger">GPT-5.5 ▾</button>
17
- <div>
18
- <button>GPT-5.5 — Flagship model</button>
19
- <button>Legacy models ▾</button>
20
- </div>
21
- </kai-popover>
22
-
23
- <script type="module">
24
- import '@kitn.ai/ui/elements'; // registers the custom elements
25
- document.querySelector('kai-popover')
26
- .addEventListener('kai-open-change', (e) => console.log('open:', e.detail.open));
27
- </script>`;
28
-
29
- const meta = {
30
- title: 'Components/Popover',
31
- tags: ['autodocs'],
32
- argTypes: argTypesFor('kai-popover'),
33
- parameters: {
34
- layout: 'centered',
35
- docs: {
36
- description: specDescription('kai-popover', [
37
- '`<kai-popover>` is the framework-agnostic **web component** for a button-and-popover card — a trigger that toggles a floating panel of arbitrary content, isolated in **Shadow DOM**. In SolidJS, use the `Popover` primitive.',
38
- '**When to use:** a "button + card" affordance — a header model menu, a settings popover, an account dropdown with mixed controls. For a flat list of commands, use a menu instead.',
39
- '**How to use:** slot the control as `slot="trigger"` and the panel as the default slot. Clicking the trigger toggles; Escape or an outside click closes (clicks inside do not). It fires `kai-open-change` with `{ open }` and accepts an `open` property for controlled use.',
40
- 'See the **Code** tab for HTML usage.',
41
- ]),
42
- },
43
- },
44
- } satisfies Meta;
45
-
46
- export default meta;
47
- type Story = StoryObj;
48
-
49
- const rowStyle = { display: 'flex', 'align-items': 'center', gap: '8px', width: '100%', padding: '6px 8px', 'border-radius': '6px', border: 'none', background: 'transparent', cursor: 'pointer', 'text-align': 'left' as const, font: 'inherit', color: 'var(--color-foreground)' };
50
- const LEGACY = ['GPT-4o', 'GPT-4.1', 'GPT-4o mini'];
51
-
52
- /** A ChatGPT-style model menu — a flagship row and an expandable group, slotted
53
- * as the popover panel. The trigger and content are your light-DOM markup. */
54
- export const ModelMenu: Story = {
55
- render: () => {
56
- let el: HTMLElement | undefined;
57
- const [legacyOpen, setLegacyOpen] = createSignal(false);
58
- onMount(() => el?.addEventListener('kai-open-change', (e) => console.log('kai-open-change', (e as CustomEvent<{ open: boolean }>).detail.open)));
59
- return (
60
- <kai-popover ref={(e) => (el = e as HTMLElement)} placement="bottom-start">
61
- <button slot="trigger" style={{ padding: '6px 12px', 'border-radius': '8px', border: '1px solid var(--color-border)', background: 'transparent', color: 'var(--color-foreground)', cursor: 'pointer', font: 'inherit' }}>
62
- GPT-5.5 ▾
63
- </button>
64
- <div style={{ width: '15rem' }}>
65
- <button type="button" style={rowStyle}>
66
- <span style={{ 'font-weight': 600 }}>GPT-5.5</span>
67
- <span style={{ 'font-size': '12px', color: 'var(--color-muted-foreground)' }}>Flagship</span>
68
- </button>
69
- <button type="button" style={rowStyle} aria-expanded={legacyOpen()} onClick={() => setLegacyOpen(!legacyOpen())}>
70
- Legacy models {legacyOpen() ? '▴' : '▾'}
71
- </button>
72
- <Show when={legacyOpen()}>
73
- <For each={LEGACY}>{(m) => <button type="button" style={{ ...rowStyle, 'padding-left': '28px' }}>{m}</button>}</For>
74
- </Show>
75
- </div>
76
- </kai-popover>
77
- );
78
- },
79
- parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } },
80
- };
@@ -1,128 +0,0 @@
1
- /**
2
- * Unit tests for parseKaiSlashCommandElement and the merge behaviour
3
- * in kai-prompt-input's declarative <kai-slash-command> reader.
4
- *
5
- * Strategy: test the exported pure helper directly with synthetic DOM elements
6
- * (no Shadow DOM, no custom element upgrade needed).
7
- * Merge behaviour is verified by constructing the same arrays the element would
8
- * produce and asserting the result — pure array logic, no browser environment needed.
9
- */
10
- import { describe, it, expect } from 'vitest';
11
- import { parseKaiSlashCommandElement } from './prompt-input';
12
-
13
- // ---------------------------------------------------------------------------
14
- // parseKaiSlashCommandElement — attribute → SlashCommandItem mapping
15
- // ---------------------------------------------------------------------------
16
-
17
- describe('parseKaiSlashCommandElement', () => {
18
- function makeEl(
19
- attrs: Record<string, string | null>,
20
- textContent?: string,
21
- ): Element {
22
- const el = document.createElement('kai-slash-command');
23
- for (const [k, v] of Object.entries(attrs)) {
24
- if (v !== null) el.setAttribute(k, v);
25
- }
26
- if (textContent !== undefined) el.textContent = textContent;
27
- return el;
28
- }
29
-
30
- it('maps command attr → id, textContent → label, description attr → description', () => {
31
- const el = makeEl(
32
- { command: 'summarize', description: 'Summarize the thread' },
33
- 'summarize',
34
- );
35
- expect(parseKaiSlashCommandElement(el)).toEqual({
36
- id: 'summarize',
37
- label: 'summarize',
38
- description: 'Summarize the thread',
39
- category: undefined,
40
- });
41
- });
42
-
43
- it('maps category attr → category', () => {
44
- const el = makeEl(
45
- { command: 'search', category: 'tools' },
46
- 'search',
47
- );
48
- expect(parseKaiSlashCommandElement(el).category).toBe('tools');
49
- });
50
-
51
- it('falls back to label attr when textContent is empty', () => {
52
- const el = makeEl({ command: 'help', label: 'Help' }, '');
53
- expect(parseKaiSlashCommandElement(el).label).toBe('Help');
54
- });
55
-
56
- it('falls back to command attr as label when both textContent and label attr are absent', () => {
57
- const el = makeEl({ command: 'debug' });
58
- expect(parseKaiSlashCommandElement(el).label).toBe('debug');
59
- });
60
-
61
- it('returns empty string for id when command attr is absent', () => {
62
- const el = makeEl({}, 'orphan');
63
- expect(parseKaiSlashCommandElement(el).id).toBe('');
64
- });
65
-
66
- it('returns undefined for optional attrs when absent', () => {
67
- const el = makeEl({ command: 'bare' }, 'bare');
68
- const item = parseKaiSlashCommandElement(el);
69
- expect(item.description).toBeUndefined();
70
- expect(item.category).toBeUndefined();
71
- });
72
-
73
- it('whitespace-trims textContent for the label', () => {
74
- const el = makeEl({ command: 'trim' }, ' trim ');
75
- expect(parseKaiSlashCommandElement(el).label).toBe('trim');
76
- });
77
- });
78
-
79
- // ---------------------------------------------------------------------------
80
- // merge behaviour — prop slashCommands + slotted children
81
- // ---------------------------------------------------------------------------
82
-
83
- describe('slashCommands merge (prop + declarative children)', () => {
84
- function makeEl(command: string, label: string, description?: string): Element {
85
- const el = document.createElement('kai-slash-command');
86
- el.setAttribute('command', command);
87
- el.textContent = label;
88
- if (description) el.setAttribute('description', description);
89
- return el;
90
- }
91
-
92
- it('prop items appear before slotted children in the merged list', () => {
93
- const propItems = [{ id: 'prop-cmd', label: 'Prop Command' }];
94
- const slottedItems = [
95
- parseKaiSlashCommandElement(makeEl('child-cmd', 'Child Command')),
96
- ];
97
- const merged = [...propItems, ...slottedItems];
98
- expect(merged[0].id).toBe('prop-cmd');
99
- expect(merged[1].id).toBe('child-cmd');
100
- });
101
-
102
- it('merged list is empty when both prop and children are absent', () => {
103
- const propItems: ReturnType<typeof parseKaiSlashCommandElement>[] = [];
104
- const slottedItems: ReturnType<typeof parseKaiSlashCommandElement>[] = [];
105
- expect([...propItems, ...slottedItems]).toHaveLength(0);
106
- });
107
-
108
- it('slotted-only: single child appears as the only item', () => {
109
- const el = makeEl('summarize', 'Summarize', 'Summarize the thread');
110
- const merged = [...[], parseKaiSlashCommandElement(el)];
111
- expect(merged).toHaveLength(1);
112
- expect(merged[0]).toEqual({
113
- id: 'summarize',
114
- label: 'Summarize',
115
- description: 'Summarize the thread',
116
- category: undefined,
117
- });
118
- });
119
-
120
- it('prop-only: prop items flow through unchanged', () => {
121
- const propItems = [
122
- { id: 'a', label: 'Alpha', description: 'First' },
123
- { id: 'b', label: 'Beta' },
124
- ];
125
- const merged = [...propItems, ...([] as typeof propItems)];
126
- expect(merged).toEqual(propItems);
127
- });
128
- });
@@ -1,88 +0,0 @@
1
- /**
2
- * Unit tests for the stoppable Stop button affordance in DefaultPromptInput.
3
- *
4
- * Strategy: test DefaultPromptInput (the Solid component) directly — the
5
- * defineWebComponent custom element requires a full browser environment
6
- * (Constructable Stylesheets, shadow roots) unsuitable for jsdom.
7
- * This mirrors the pattern in prompt-suggestions.declarative.test.tsx.
8
- */
9
- import { describe, it, expect, vi, afterEach } from 'vitest';
10
- import '@testing-library/jest-dom/vitest';
11
- import { render, cleanup, fireEvent } from '@solidjs/testing-library';
12
- import { DefaultPromptInput } from './default-input';
13
-
14
- afterEach(cleanup);
15
-
16
- const noop = () => {};
17
- const baseProps = {
18
- value: '',
19
- onValueChange: noop,
20
- onSubmit: noop,
21
- onSuggestionClick: noop,
22
- };
23
-
24
- describe('DefaultPromptInput stoppable Stop button', () => {
25
- it('renders the send button (not Stop) when loading=false stoppable=false', () => {
26
- const { getByTestId, queryByTestId } = render(() => (
27
- <DefaultPromptInput {...baseProps} loading={false} stoppable={false} />
28
- ));
29
- expect(getByTestId('send')).toBeInTheDocument();
30
- expect(queryByTestId('stop')).not.toBeInTheDocument();
31
- });
32
-
33
- it('renders the send button (not Stop) when stoppable=true but loading=false', () => {
34
- const { getByTestId, queryByTestId } = render(() => (
35
- <DefaultPromptInput {...baseProps} loading={false} stoppable={true} />
36
- ));
37
- expect(getByTestId('send')).toBeInTheDocument();
38
- expect(queryByTestId('stop')).not.toBeInTheDocument();
39
- });
40
-
41
- it('renders the send button (not Stop) when loading=true but stoppable=false', () => {
42
- const { getByTestId, queryByTestId } = render(() => (
43
- <DefaultPromptInput {...baseProps} loading={true} stoppable={false} />
44
- ));
45
- expect(getByTestId('send')).toBeInTheDocument();
46
- expect(queryByTestId('stop')).not.toBeInTheDocument();
47
- });
48
-
49
- it('renders the Stop button (not send) when both loading=true and stoppable=true', () => {
50
- const { getByTestId, queryByTestId } = render(() => (
51
- <DefaultPromptInput {...baseProps} loading={true} stoppable={true} />
52
- ));
53
- expect(getByTestId('stop')).toBeInTheDocument();
54
- expect(queryByTestId('send')).not.toBeInTheDocument();
55
- });
56
-
57
- it('Stop button has accessible label "Stop"', () => {
58
- const { getByLabelText } = render(() => (
59
- <DefaultPromptInput {...baseProps} loading={true} stoppable={true} />
60
- ));
61
- expect(getByLabelText('Stop')).toBeInTheDocument();
62
- });
63
-
64
- it('clicking the Stop button calls onStop', () => {
65
- const onStop = vi.fn();
66
- const { getByTestId } = render(() => (
67
- <DefaultPromptInput {...baseProps} loading={true} stoppable={true} onStop={onStop} />
68
- ));
69
- fireEvent.click(getByTestId('stop'));
70
- expect(onStop).toHaveBeenCalledOnce();
71
- });
72
-
73
- it('clicking the Stop button does NOT call onSubmit', () => {
74
- const onSubmit = vi.fn();
75
- const onStop = vi.fn();
76
- const { getByTestId } = render(() => (
77
- <DefaultPromptInput
78
- {...baseProps}
79
- onSubmit={onSubmit}
80
- loading={true}
81
- stoppable={true}
82
- onStop={onStop}
83
- />
84
- ));
85
- fireEvent.click(getByTestId('stop'));
86
- expect(onSubmit).not.toHaveBeenCalled();
87
- });
88
- });
@@ -1,120 +0,0 @@
1
- /**
2
- * Unit tests for custom `<kai-action>` toolbar buttons in DefaultPromptInput.
3
- *
4
- * Strategy: test DefaultPromptInput (the Solid component) directly — the
5
- * defineWebComponent custom element requires a full browser environment
6
- * (Constructable Stylesheets, shadow roots) unsuitable for jsdom.
7
- * This mirrors the pattern in prompt-input-stoppable.test.tsx.
8
- */
9
- import { describe, it, expect, vi, afterEach } from 'vitest';
10
- import '@testing-library/jest-dom/vitest';
11
- import { render, cleanup, fireEvent } from '@solidjs/testing-library';
12
- import { DefaultPromptInput } from './default-input';
13
- import type { CustomAction } from './chat-types';
14
-
15
- afterEach(cleanup);
16
-
17
- const noop = () => {};
18
- const baseProps = {
19
- value: '',
20
- onValueChange: noop,
21
- onSubmit: noop,
22
- onSuggestionClick: noop,
23
- };
24
-
25
- const ACTIONS: CustomAction[] = [
26
- { id: 'attach', label: 'Attach', icon: 'paperclip', tooltip: 'Attach file' },
27
- { id: 'bookmark', label: 'Bookmark', icon: 'bookmark', tooltip: 'Save for later' },
28
- ];
29
-
30
- describe('DefaultPromptInput custom toolbar actions', () => {
31
- it('renders no custom buttons when toolbarActions is empty', () => {
32
- const { queryByRole } = render(() => (
33
- <DefaultPromptInput {...baseProps} toolbarActions={[]} />
34
- ));
35
- // The send button is the only button when no custom actions are set.
36
- // (paperclip attach is absent because onAttachmentsChange is not provided)
37
- const buttons = queryByRole('button', { name: 'Attach' });
38
- expect(buttons).not.toBeInTheDocument();
39
- });
40
-
41
- it('renders one ghost button per custom action', () => {
42
- const { getAllByRole } = render(() => (
43
- <DefaultPromptInput {...baseProps} toolbarActions={ACTIONS} />
44
- ));
45
- // aria-label is set to action.label on each button
46
- const attachBtn = getAllByRole('button').find(
47
- (b) => b.getAttribute('aria-label') === 'Attach',
48
- );
49
- const bookmarkBtn = getAllByRole('button').find(
50
- (b) => b.getAttribute('aria-label') === 'Bookmark',
51
- );
52
- expect(attachBtn).toBeInTheDocument();
53
- expect(bookmarkBtn).toBeInTheDocument();
54
- });
55
-
56
- it('sets data-action attribute to the action id', () => {
57
- const { getAllByRole } = render(() => (
58
- <DefaultPromptInput {...baseProps} toolbarActions={ACTIONS} />
59
- ));
60
- const attachBtn = getAllByRole('button').find(
61
- (b) => b.getAttribute('aria-label') === 'Attach',
62
- );
63
- expect(attachBtn).toHaveAttribute('data-action', 'attach');
64
- });
65
-
66
- it('clicking a custom action button calls onAction with the action id', () => {
67
- const onAction = vi.fn();
68
- const { getAllByRole } = render(() => (
69
- <DefaultPromptInput {...baseProps} toolbarActions={ACTIONS} onAction={onAction} />
70
- ));
71
- const attachBtn = getAllByRole('button').find(
72
- (b) => b.getAttribute('aria-label') === 'Attach',
73
- )!;
74
- fireEvent.click(attachBtn);
75
- expect(onAction).toHaveBeenCalledOnce();
76
- expect(onAction).toHaveBeenCalledWith('attach');
77
- });
78
-
79
- it('clicking the second action button fires onAction with its id', () => {
80
- const onAction = vi.fn();
81
- const { getAllByRole } = render(() => (
82
- <DefaultPromptInput {...baseProps} toolbarActions={ACTIONS} onAction={onAction} />
83
- ));
84
- const bookmarkBtn = getAllByRole('button').find(
85
- (b) => b.getAttribute('aria-label') === 'Bookmark',
86
- )!;
87
- fireEvent.click(bookmarkBtn);
88
- expect(onAction).toHaveBeenCalledWith('bookmark');
89
- });
90
-
91
- it('clicking a custom action does NOT call onSubmit', () => {
92
- const onSubmit = vi.fn();
93
- const onAction = vi.fn();
94
- const { getAllByRole } = render(() => (
95
- <DefaultPromptInput
96
- {...baseProps}
97
- onSubmit={onSubmit}
98
- toolbarActions={ACTIONS}
99
- onAction={onAction}
100
- />
101
- ));
102
- const attachBtn = getAllByRole('button').find(
103
- (b) => b.getAttribute('aria-label') === 'Attach',
104
- )!;
105
- fireEvent.click(attachBtn);
106
- expect(onSubmit).not.toHaveBeenCalled();
107
- });
108
-
109
- it('renders a label-only button when the icon name is unknown', () => {
110
- const unknownIconAction: CustomAction[] = [
111
- { id: 'mystery', label: 'Mystery', icon: 'not-a-real-icon' },
112
- ];
113
- const { getByRole } = render(() => (
114
- <DefaultPromptInput {...baseProps} toolbarActions={unknownIconAction} />
115
- ));
116
- // aria-label is still set to the label
117
- const btn = getByRole('button', { name: 'Mystery' });
118
- expect(btn).toBeInTheDocument();
119
- });
120
- });