@kitnai/chat 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/README.md +9 -9
  2. package/dist/custom-elements.json +1676 -881
  3. package/dist/kitn-chat.es.js +36 -36
  4. package/dist/llms/llms-full.txt +316 -155
  5. package/dist/llms/llms.txt +18 -18
  6. package/dist/schemas/card-envelope.schema.json +14 -0
  7. package/dist/schemas/card-event.schema.json +12 -0
  8. package/dist/schemas/confirm.schema.json +65 -0
  9. package/dist/schemas/embed.schema.json +65 -0
  10. package/dist/schemas/form.result.schema.json +7 -0
  11. package/dist/schemas/form.schema.json +33 -0
  12. package/dist/schemas/link.schema.json +56 -0
  13. package/dist/schemas/task-list.result.schema.json +16 -0
  14. package/dist/schemas/task-list.schema.json +78 -0
  15. package/dist/theme.tokens.css +65 -65
  16. package/dist/tsx-B8rCNbgL.js +1 -0
  17. package/dist/typescript-RycA9KXf.js +1 -0
  18. package/frameworks/react/index.tsx +382 -193
  19. package/frameworks/react/runtime.tsx +2 -2
  20. package/llms-full.txt +316 -155
  21. package/llms.txt +18 -18
  22. package/package.json +5 -2
  23. package/src/components/artifact.stories.tsx +138 -0
  24. package/src/components/artifact.tsx +581 -0
  25. package/src/components/attachments.stories.tsx +7 -8
  26. package/src/components/attachments.tsx +2 -2
  27. package/src/components/card.tsx +110 -0
  28. package/src/components/chain-of-thought.stories.tsx +7 -8
  29. package/src/components/chat-container.stories.tsx +7 -8
  30. package/src/components/chat-container.tsx +4 -0
  31. package/src/components/checkpoint.stories.tsx +7 -8
  32. package/src/components/code-block.stories.tsx +8 -9
  33. package/src/components/component-meta.json +3411 -0
  34. package/src/components/confirm-card.stories.tsx +74 -0
  35. package/src/components/confirm-card.tsx +299 -0
  36. package/src/components/context.stories.tsx +7 -8
  37. package/src/components/conversation-item.stories.tsx +7 -8
  38. package/src/components/conversation-item.tsx +2 -2
  39. package/src/components/conversation-list.stories.tsx +7 -8
  40. package/src/components/conversation-list.tsx +1 -1
  41. package/src/components/embed.tsx +196 -0
  42. package/src/components/empty.stories.tsx +8 -9
  43. package/src/components/feedback-bar.stories.tsx +7 -8
  44. package/src/components/file-tree.stories.tsx +73 -0
  45. package/src/components/file-tree.tsx +383 -0
  46. package/src/components/file-upload.stories.tsx +7 -8
  47. package/src/components/form-widgets.tsx +461 -0
  48. package/src/components/form.tsx +796 -0
  49. package/src/components/image.stories.tsx +7 -8
  50. package/src/components/link-card.tsx +194 -0
  51. package/src/components/loader.stories.tsx +7 -8
  52. package/src/components/markdown.stories.tsx +7 -8
  53. package/src/components/message-narrow.stories.tsx +12 -13
  54. package/src/components/message-skills.stories.tsx +16 -17
  55. package/src/components/message.stories.tsx +17 -18
  56. package/src/components/model-switcher.stories.tsx +7 -8
  57. package/src/components/prompt-input.stories.tsx +8 -9
  58. package/src/components/prompt-suggestion.stories.tsx +7 -8
  59. package/src/components/prompt-suggestion.tsx +3 -3
  60. package/src/components/reasoning.stories.tsx +7 -8
  61. package/src/components/scroll-button.stories.tsx +7 -8
  62. package/src/components/slash-command.stories.tsx +8 -9
  63. package/src/components/slash-command.tsx +2 -2
  64. package/src/components/source.stories.tsx +7 -8
  65. package/src/components/source.tsx +1 -1
  66. package/src/components/task-list-card.stories.tsx +78 -0
  67. package/src/components/task-list-card.tsx +388 -0
  68. package/src/components/text-shimmer.stories.tsx +7 -8
  69. package/src/components/thinking-bar.stories.tsx +7 -8
  70. package/src/components/tool.stories.tsx +7 -8
  71. package/src/components/tool.tsx +2 -2
  72. package/src/components/voice-input.stories.tsx +7 -8
  73. package/src/elements/artifact.stories.tsx +291 -0
  74. package/src/elements/artifact.tsx +72 -0
  75. package/src/elements/{kitn-attachments.stories.tsx → attachments.stories.tsx} +11 -11
  76. package/src/elements/attachments.tsx +4 -4
  77. package/src/elements/card.stories.tsx +118 -0
  78. package/src/elements/card.tsx +40 -0
  79. package/src/elements/catalog.stories.tsx +491 -0
  80. package/src/elements/{kitn-chain-of-thought.stories.tsx → chain-of-thought.stories.tsx} +13 -13
  81. package/src/elements/chain-of-thought.tsx +3 -3
  82. package/src/elements/{kitn-chat-scope-picker.stories.tsx → chat-scope-picker.stories.tsx} +10 -10
  83. package/src/elements/chat-scope-picker.tsx +4 -4
  84. package/src/elements/{kitn-chat-workspace.stories.tsx → chat-workspace.stories.tsx} +71 -29
  85. package/src/elements/chat-workspace.tsx +29 -3
  86. package/src/elements/{kitn-chat.stories.tsx → chat.stories.tsx} +61 -16
  87. package/src/elements/chat.tsx +23 -2
  88. package/src/elements/{kitn-checkpoint.stories.tsx → checkpoint.stories.tsx} +11 -11
  89. package/src/elements/checkpoint.tsx +4 -4
  90. package/src/elements/{kitn-code-block.stories.tsx → code-block.stories.tsx} +10 -10
  91. package/src/elements/code-block.tsx +3 -3
  92. package/src/elements/compiled.css +1 -1
  93. package/src/elements/composed-shell.stories.tsx +316 -0
  94. package/src/elements/confirm-card.stories.tsx +186 -0
  95. package/src/elements/confirm-card.tsx +45 -0
  96. package/src/elements/{kitn-context-meter.stories.tsx → context-meter.stories.tsx} +10 -10
  97. package/src/elements/context-meter.tsx +3 -3
  98. package/src/elements/{kitn-conversation-list.stories.tsx → conversation-list.stories.tsx} +35 -22
  99. package/src/elements/conversation-list.tsx +11 -2
  100. package/src/elements/css.ts +1 -1
  101. package/src/elements/define.tsx +10 -10
  102. package/src/elements/element-meta.json +2649 -0
  103. package/src/elements/element-types.d.ts +251 -125
  104. package/src/elements/embed.stories.tsx +197 -0
  105. package/src/elements/embed.tsx +35 -0
  106. package/src/elements/{kitn-empty.stories.tsx → empty.stories.tsx} +12 -12
  107. package/src/elements/empty.tsx +3 -3
  108. package/src/elements/{kitn-feedback-bar.stories.tsx → feedback-bar.stories.tsx} +11 -11
  109. package/src/elements/feedback-bar.tsx +4 -4
  110. package/src/elements/file-tree.stories.tsx +133 -0
  111. package/src/elements/file-tree.tsx +52 -0
  112. package/src/elements/{kitn-file-upload.stories.tsx → file-upload.stories.tsx} +12 -12
  113. package/src/elements/file-upload.tsx +4 -4
  114. package/src/elements/form.stories.tsx +204 -0
  115. package/src/elements/form.tsx +37 -0
  116. package/src/elements/{kitn-image.stories.tsx → image.stories.tsx} +10 -10
  117. package/src/elements/image.tsx +3 -3
  118. package/src/elements/link-card.stories.tsx +193 -0
  119. package/src/elements/link-card.tsx +34 -0
  120. package/src/elements/{kitn-loader.stories.tsx → loader.stories.tsx} +11 -11
  121. package/src/elements/loader.tsx +3 -3
  122. package/src/elements/{kitn-markdown.stories.tsx → markdown.stories.tsx} +10 -10
  123. package/src/elements/markdown.tsx +3 -3
  124. package/src/elements/{kitn-message-skills.stories.tsx → message-skills.stories.tsx} +10 -10
  125. package/src/elements/message-skills.tsx +3 -3
  126. package/src/elements/{kitn-message.stories.tsx → message.stories.tsx} +12 -12
  127. package/src/elements/message.tsx +5 -5
  128. package/src/elements/{kitn-model-switcher.stories.tsx → model-switcher.stories.tsx} +10 -10
  129. package/src/elements/model-switcher.tsx +5 -5
  130. package/src/elements/{kitn-prompt-input.stories.tsx → prompt-input.stories.tsx} +41 -19
  131. package/src/elements/prompt-input.tsx +5 -5
  132. package/src/elements/{kitn-prompt-suggestions.stories.tsx → prompt-suggestions.stories.tsx} +13 -13
  133. package/src/elements/prompt-suggestions.tsx +4 -4
  134. package/src/elements/{kitn-reasoning.stories.tsx → reasoning.stories.tsx} +10 -10
  135. package/src/elements/reasoning.tsx +4 -4
  136. package/src/elements/register.ts +11 -1
  137. package/src/elements/resizable.stories.tsx +200 -0
  138. package/src/elements/resizable.tsx +264 -0
  139. package/src/elements/{kitn-response-stream.stories.tsx → response-stream.stories.tsx} +10 -10
  140. package/src/elements/response-stream.tsx +4 -4
  141. package/src/elements/{kitn-source-list.stories.tsx → source-list.stories.tsx} +11 -11
  142. package/src/elements/{kitn-source.stories.tsx → source.stories.tsx} +12 -12
  143. package/src/elements/source.tsx +5 -5
  144. package/src/elements/styles.css +140 -1
  145. package/src/elements/task-list-card.stories.tsx +194 -0
  146. package/src/elements/task-list-card.tsx +40 -0
  147. package/src/elements/{kitn-text-shimmer.stories.tsx → text-shimmer.stories.tsx} +10 -10
  148. package/src/elements/text-shimmer.tsx +3 -3
  149. package/src/elements/{kitn-thinking-bar.stories.tsx → thinking-bar.stories.tsx} +11 -11
  150. package/src/elements/thinking-bar.tsx +5 -5
  151. package/src/elements/{kitn-tool.stories.tsx → tool.stories.tsx} +10 -10
  152. package/src/elements/tool.tsx +3 -3
  153. package/src/elements/{kitn-voice-input.stories.tsx → voice-input.stories.tsx} +10 -10
  154. package/src/elements/voice-input.tsx +4 -4
  155. package/src/index.ts +94 -2
  156. package/src/primitives/card-contract.ts +60 -0
  157. package/src/primitives/card-host.tsx +35 -0
  158. package/src/primitives/card-routing.ts +79 -0
  159. package/src/primitives/card-schemas/card-envelope.schema.json +14 -0
  160. package/src/primitives/card-schemas/card-event.schema.json +12 -0
  161. package/src/primitives/card-schemas/confirm.schema.json +65 -0
  162. package/src/primitives/card-schemas/embed.schema.json +65 -0
  163. package/src/primitives/card-schemas/form.result.schema.json +7 -0
  164. package/src/primitives/card-schemas/form.schema.json +33 -0
  165. package/src/primitives/card-schemas/link.schema.json +56 -0
  166. package/src/primitives/card-schemas/task-list.result.schema.json +16 -0
  167. package/src/primitives/card-schemas/task-list.schema.json +78 -0
  168. package/src/primitives/card-validate.ts +95 -0
  169. package/src/primitives/embed-providers.ts +254 -0
  170. package/src/primitives/highlighter.ts +4 -0
  171. package/src/primitives/link-preview.ts +87 -0
  172. package/src/primitives/pdf-preview.ts +121 -0
  173. package/src/stories/chat-panel-layout.stories.tsx +2 -1
  174. package/src/stories/chat-scene.tsx +22 -21
  175. package/src/stories/checkpoint-restore.stories.tsx +10 -10
  176. package/src/stories/conversation-with-reasoning.stories.tsx +4 -4
  177. package/src/stories/conversation-with-sources.stories.tsx +7 -7
  178. package/src/stories/docs/Accessibility.mdx +2 -2
  179. package/src/stories/docs/ForAIAgents.mdx +3 -3
  180. package/src/stories/docs/GettingStarted.mdx +2 -2
  181. package/src/stories/docs/Installation.mdx +2 -2
  182. package/src/stories/docs/Integrations.mdx +29 -29
  183. package/src/stories/docs/Introduction.mdx +3 -3
  184. package/src/stories/docs/Theming.mdx +2 -2
  185. package/src/stories/docs/element-controls.ts +60 -0
  186. package/src/stories/docs/theme-editor/theme-editor.tsx +1 -0
  187. package/src/stories/examples/ChoosingComponents.mdx +94 -0
  188. package/src/stories/examples/sample-data.ts +79 -0
  189. package/src/stories/message-actions.stories.tsx +13 -13
  190. package/src/stories/pattern-centered-conversation.stories.tsx +3 -3
  191. package/src/stories/pattern-docked-widget.stories.tsx +1 -1
  192. package/src/stories/pattern-empty-state.stories.tsx +3 -3
  193. package/src/stories/prompt-input-variants.stories.tsx +13 -13
  194. package/src/stories/streaming-response.stories.tsx +3 -3
  195. package/src/stories/typography.stories.tsx +4 -4
  196. package/src/ui/avatar.stories.tsx +7 -8
  197. package/src/ui/badge.stories.tsx +7 -8
  198. package/src/ui/button.stories.tsx +8 -9
  199. package/src/ui/button.tsx +1 -0
  200. package/src/ui/collapsible.stories.tsx +6 -7
  201. package/src/ui/dropdown.stories.tsx +6 -7
  202. package/src/ui/hover-card.stories.tsx +6 -7
  203. package/src/ui/resizable.stories.tsx +74 -9
  204. package/src/ui/resizable.tsx +351 -71
  205. package/src/ui/scroll-area.stories.tsx +6 -7
  206. package/src/ui/scroll-area.tsx +3 -1
  207. package/src/ui/separator.stories.tsx +7 -8
  208. package/src/ui/skeleton.stories.tsx +7 -8
  209. package/src/ui/textarea.stories.tsx +6 -7
  210. package/src/ui/tooltip.stories.tsx +8 -9
  211. package/theme.css +65 -65
@@ -0,0 +1,118 @@
1
+ import type { Meta, StoryObj } from 'storybook-solidjs-vite';
2
+ import type { JSX } from 'solid-js';
3
+ import './card';
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
+ 'kc-card': JSX.HTMLAttributes<HTMLElement> & {
11
+ heading?: string;
12
+ description?: string;
13
+ 'error-message'?: string;
14
+ dense?: boolean | string;
15
+ };
16
+ }
17
+ }
18
+ }
19
+
20
+ /** A bordered box the card sits inside (gives it a sensible width). */
21
+ function Frame(props: { children: JSX.Element }) {
22
+ return <div style={{ 'max-width': '420px' }}>{props.children}</div>;
23
+ }
24
+
25
+ const PLAYGROUND_SNIPPET = `<!-- Works in any framework or plain HTML -->
26
+ <kc-card heading="Invite teammates" description="They'll get an email to join.">
27
+ <p>Add the people you want in this workspace.</p>
28
+ <div slot="actions">
29
+ <button>Cancel</button>
30
+ <button>Send invites</button>
31
+ </div>
32
+ </kc-card>
33
+
34
+ <script type="module">
35
+ import '@kitnai/chat/elements'; // registers the custom elements
36
+ </script>`;
37
+
38
+ const MEDIA_SNIPPET = `<kc-card heading="Quarterly report" description="Generated just now.">
39
+ <img slot="media" src="/preview.png" alt="Report preview" />
40
+ <p>Your Q2 numbers are ready to review.</p>
41
+ </kc-card>`;
42
+
43
+ const ERROR_SNIPPET = `<!-- The one consistent inline error every card uses. -->
44
+ <kc-card heading="Share your feedback" error-message="This card couldn't be displayed."></kc-card>`;
45
+
46
+ const meta = {
47
+ title: 'Generative UI/Cards/kc-card',
48
+ tags: ['autodocs'],
49
+ argTypes: argTypesFor('kc-card'),
50
+ parameters: {
51
+ layout: 'padded',
52
+ docs: {
53
+ description: specDescription('kc-card', [
54
+ '`<kc-card>` is the shared, presentational **card chrome** every native generative-UI card composes from: an optional **media** region (`slot="media"`), a **heading** + **description**, a **body** (default slot), an **actions** footer (`slot="actions"`), and one consistent inline **error** state (`error-message`).',
55
+ '**It emits no events and reads no context** — it is chrome only. The cards that compose it (e.g. `<kc-form>`) own the Card-contract interaction. It ships public so you can also use it as a plain themed surface.',
56
+ "**How to use:** register once with `import '@kitnai/chat/elements'`, set `heading`/`description` attributes, drop body markup in the default slot, footer buttons in `slot=\"actions\"`, and media in `slot=\"media\"`. Set `error-message` to render the standard inline error (it replaces the body/actions).",
57
+ 'See the **Code** tab for HTML usage.',
58
+ ]),
59
+ },
60
+ },
61
+ } satisfies Meta;
62
+
63
+ export default meta;
64
+ type Story = StoryObj;
65
+
66
+ /** Heading + description + body + two footer buttons. */
67
+ export const Playground: Story = {
68
+ render: () => (
69
+ <Frame>
70
+ <kc-card heading="Invite teammates" description="They'll get an email to join.">
71
+ <p style={{ margin: 0 }}>Add the people you want in this workspace.</p>
72
+ <div slot="actions" style={{ display: 'flex', gap: '8px' }}>
73
+ <button>Cancel</button>
74
+ <button>Send invites</button>
75
+ </div>
76
+ </kc-card>
77
+ </Frame>
78
+ ),
79
+ parameters: { docs: { source: { code: PLAYGROUND_SNIPPET, language: 'html' } } },
80
+ };
81
+
82
+ /** An image media region above the heading. */
83
+ export const WithMedia: Story = {
84
+ render: () => (
85
+ <Frame>
86
+ <kc-card heading="Quarterly report" description="Generated just now.">
87
+ <div
88
+ slot="media"
89
+ style={{
90
+ height: '120px',
91
+ display: 'grid',
92
+ 'place-items': 'center',
93
+ background: 'var(--color-muted, #f4f4f5)',
94
+ color: 'var(--color-muted-foreground, #71717a)',
95
+ 'font-size': '13px',
96
+ }}
97
+ >
98
+ media slot
99
+ </div>
100
+ <p style={{ margin: 0 }}>Your Q2 numbers are ready to review.</p>
101
+ </kc-card>
102
+ </Frame>
103
+ ),
104
+ parameters: { docs: { source: { code: MEDIA_SNIPPET, language: 'html' } } },
105
+ };
106
+
107
+ /** The standard inline error state (replaces the body/actions). */
108
+ export const ErrorState: Story = {
109
+ render: () => (
110
+ <Frame>
111
+ <kc-card
112
+ heading="Share your feedback"
113
+ error-message="This card couldn't be displayed."
114
+ />
115
+ </Frame>
116
+ ),
117
+ parameters: { docs: { source: { code: ERROR_SNIPPET, language: 'html' } } },
118
+ };
@@ -0,0 +1,40 @@
1
+ import { defineWebComponent } from './define';
2
+ import { Card } from '../components/card';
3
+
4
+ interface Props extends Record<string, unknown> {
5
+ /** Heading rendered in the card chrome (= CardEnvelope.title). Attribute: `heading`. */
6
+ heading?: string;
7
+ /** Supporting text under the heading. Attribute: `description`. */
8
+ description?: string;
9
+ /** When set, the card renders its inline error state instead of the body.
10
+ * Attribute: `error-message`. */
11
+ errorMessage?: string;
12
+ /** Compact spacing for dense lists. Attribute: `dense`. */
13
+ dense?: boolean;
14
+ }
15
+
16
+ /**
17
+ * `<kc-card>` — the shared, presentational card chrome every native card composes
18
+ * from: an optional media region (`slot="media"`), a heading + description, a body
19
+ * (default slot), an actions footer (`slot="actions"`), and one consistent inline
20
+ * **error** state (`error-message`). It emits **no** events and reads no context —
21
+ * it is chrome only; the cards that compose it (e.g. `<kc-form>`) own the contract
22
+ * interaction. Isolated in Shadow DOM; theme-aware via the shared kit tokens.
23
+ */
24
+ defineWebComponent<Props>('kc-card', {
25
+ heading: undefined,
26
+ description: undefined,
27
+ errorMessage: undefined,
28
+ dense: false,
29
+ }, (props, { flag }) => (
30
+ <Card
31
+ heading={props.heading}
32
+ description={props.description}
33
+ errorMessage={props.errorMessage}
34
+ dense={flag('dense')}
35
+ media={<slot name="media" />}
36
+ actions={<slot name="actions" />}
37
+ >
38
+ <slot />
39
+ </Card>
40
+ ));
@@ -0,0 +1,491 @@
1
+ import type { Meta, StoryObj } from 'storybook-solidjs-vite';
2
+ import { onMount, type JSX } from 'solid-js';
3
+ import './register'; // side effect: registers the custom elements
4
+ import {
5
+ attachments,
6
+ conversations,
7
+ context,
8
+ cotSteps,
9
+ models,
10
+ assistantMessage,
11
+ userMessage,
12
+ slashCommands,
13
+ sources,
14
+ } from '../stories/examples/sample-data';
15
+
16
+ /**
17
+ * Examples / Catalog — the `examples/composable/index.html` showcase, ported into
18
+ * Storybook as source-visible web-component stories. Every kc-* element rendered
19
+ * with minimal sample data, grouped by category, so a developer can answer
20
+ * "what exists?" without leaving Storybook — and read the exact markup via the
21
+ * "Show code" panel on each story.
22
+ *
23
+ * Convention (matches the per-element stories): the kc-* tags are custom DOM
24
+ * elements declared as JSX intrinsics elsewhere with only the standard
25
+ * attributes; element-specific attributes and object/array PROPERTIES are set
26
+ * imperatively through a `ref` (see `wire`/`attrs`/`props`), so this file stays
27
+ * type-safe without re-declaring the tags.
28
+ */
29
+
30
+ type AnyEl = HTMLElement & Record<string, unknown>;
31
+
32
+ /** Set JS properties (objects/arrays) on an element. */
33
+ const props = (el: HTMLElement, p: Record<string, unknown>) => {
34
+ for (const k in p) (el as AnyEl)[k] = p[k];
35
+ };
36
+ /** Set string/boolean attributes on an element. */
37
+ const attrs = (el: HTMLElement, a: Record<string, string | boolean>) => {
38
+ for (const k in a) {
39
+ const v = a[k];
40
+ if (v === false) el.removeAttribute(k);
41
+ else el.setAttribute(k, v === true ? '' : v);
42
+ }
43
+ };
44
+
45
+ // The kc-* tags are declared as JSX intrinsics by the per-element story files
46
+ // (global `declare module 'solid-js'` augmentations). We only ever pass `style`
47
+ // and `ref` here, so no local re-declaration is needed.
48
+
49
+ // ── helpers ────────────────────────────────────────────────────────────────
50
+
51
+ /** A bordered tile that frames one component with a caption. */
52
+ function Spec(props: { tag: string; note?: string; children: JSX.Element; tall?: boolean }) {
53
+ return (
54
+ <div
55
+ style={{
56
+ border: '1px solid var(--color-border, #e4e4e7)',
57
+ 'border-radius': '12px',
58
+ overflow: 'hidden',
59
+ background: 'var(--color-background, #fff)',
60
+ display: 'flex',
61
+ 'flex-direction': 'column',
62
+ }}
63
+ >
64
+ <div
65
+ style={{
66
+ padding: '8px 12px',
67
+ 'border-bottom': '1px solid var(--color-border, #e4e4e7)',
68
+ 'font-size': '12px',
69
+ display: 'flex',
70
+ gap: '8px',
71
+ 'align-items': 'baseline',
72
+ 'flex-wrap': 'wrap',
73
+ }}
74
+ >
75
+ <code style={{ 'font-weight': '600', color: 'var(--color-foreground, #18181b)' }}>{props.tag}</code>
76
+ {props.note ? (
77
+ <span style={{ color: 'var(--color-muted-foreground, #71717a)' }}>{props.note}</span>
78
+ ) : null}
79
+ </div>
80
+ <div style={{ padding: '14px', 'min-height': props.tall ? '320px' : 'auto' }}>{props.children}</div>
81
+ </div>
82
+ );
83
+ }
84
+
85
+ /** Responsive grid of Spec tiles. */
86
+ function Grid(props: { children: JSX.Element }) {
87
+ return (
88
+ <div
89
+ style={{
90
+ display: 'grid',
91
+ 'grid-template-columns': 'repeat(auto-fill, minmax(320px, 1fr))',
92
+ gap: '16px',
93
+ 'max-width': '1100px',
94
+ }}
95
+ >
96
+ {props.children}
97
+ </div>
98
+ );
99
+ }
100
+
101
+ const meta = {
102
+ title: 'Examples/Catalog',
103
+ parameters: {
104
+ layout: 'padded',
105
+ docs: {
106
+ description: {
107
+ component: [
108
+ '# Component catalog',
109
+ 'Every `kc-*` web component rendered with minimal sample data, grouped by category — the in-Storybook port of `examples/composable/index.html`. Use it to answer **"what exists?"**, then open each story\'s **Show code** panel to read the exact composition markup.',
110
+ 'Data goes **in via properties** (set with `el.someProp = …` — see each snippet), interactions come **out via events** (`el.addEventListener("submit", …)`). Register everything once with `import "@kitnai/chat/elements"`.',
111
+ 'Next: see **Examples / Composed chat shell** to watch these leaves assemble into a real chat, and **Examples / Choosing components** for the mental model of which tier to reach for.',
112
+ ].join('\n\n'),
113
+ },
114
+ },
115
+ },
116
+ } satisfies Meta;
117
+
118
+ export default meta;
119
+ type Story = StoryObj;
120
+
121
+ // ── 01 · Batteries-included ──────────────────────────────────────────────────
122
+
123
+ const DROPIN_SNIPPET = `<!-- The drop-in layer: whole surfaces in a single tag -->
124
+ <kc-conversations style="display:block;height:320px"></kc-conversations>
125
+ <kc-prompt-input placeholder="Ask anything… (try typing /)"></kc-prompt-input>
126
+
127
+ <script type="module">
128
+ import '@kitnai/chat/elements';
129
+
130
+ const list = document.querySelector('kc-conversations');
131
+ list.conversations = [
132
+ { id: 'c1', title: 'Web component architecture', scope: { type: 'document' },
133
+ messageCount: 12, lastMessageAt: '…', updatedAt: '…' },
134
+ ];
135
+ list.activeId = 'c1';
136
+ list.addEventListener('select', (e) => (list.activeId = e.detail.id));
137
+
138
+ const input = document.querySelector('kc-prompt-input');
139
+ input.slashCommands = [
140
+ { id: 'summarize', label: '/summarize', description: 'Summarize', category: 'Actions' },
141
+ ];
142
+ input.addEventListener('submit', (e) => console.log('submit', e.detail.value));
143
+ </script>`;
144
+
145
+ export const BatteriesIncluded: Story = {
146
+ name: '01 · Batteries-included',
147
+ render: () => {
148
+ let list!: HTMLElement;
149
+ let input!: HTMLElement;
150
+ onMount(() => {
151
+ props(list, { conversations, activeId: 'c1' });
152
+ list.addEventListener('select', (e) => ((list as AnyEl).activeId = (e as CustomEvent).detail.id));
153
+ props(input, { slashCommands });
154
+ attrs(input, { placeholder: 'Ask anything… (try typing /)' });
155
+ });
156
+ return (
157
+ <Grid>
158
+ <Spec tag="kc-conversations" note="sidebar list with grouping & selection" tall>
159
+ <div style={{ height: '300px', border: '1px solid var(--color-border,#e4e4e7)', 'border-radius': '8px', overflow: 'hidden' }}>
160
+ <kc-conversations ref={(e) => (list = e)} style={{ display: 'block', height: '100%' }} />
161
+ </div>
162
+ </Spec>
163
+ <Spec tag="kc-prompt-input" note='slash commands — type "/"'>
164
+ <kc-prompt-input ref={(e) => (input = e)} />
165
+ </Spec>
166
+ </Grid>
167
+ );
168
+ },
169
+ parameters: { docs: { source: { code: DROPIN_SNIPPET, language: 'html' } } },
170
+ };
171
+
172
+ // ── 02 · Messages ────────────────────────────────────────────────────────────
173
+
174
+ const MESSAGES_SNIPPET = `<!-- Compose your own message list from the parts a turn is made of -->
175
+ <kc-message id="assistant"></kc-message>
176
+ <kc-message id="user"></kc-message>
177
+ <kc-markdown id="md"></kc-markdown>
178
+ <kc-reasoning id="reason" label="Reasoning" streaming></kc-reasoning>
179
+ <kc-chain-of-thought id="cot"></kc-chain-of-thought>
180
+ <kc-code-block id="code" language="ts"></kc-code-block>
181
+ <kc-tool id="tool" open></kc-tool>
182
+
183
+ <script type="module">
184
+ import '@kitnai/chat/elements';
185
+
186
+ document.getElementById('assistant').message = {
187
+ id: 'm-a', role: 'assistant',
188
+ content: "Here's the plan…\\n\`\`\`js\\nconst kit = useKitn();\\n\`\`\`",
189
+ reasoning: { text: 'The user wants X…', label: 'Reasoning' },
190
+ tools: [{ type: 'search', state: 'output-available', input: { query: 'kitn' }, output: { hits: 3 } }],
191
+ actions: ['copy', 'like', 'dislike', 'regenerate'],
192
+ };
193
+ document.getElementById('user').message = { id: 'm-u', role: 'user', content: 'How do I compose these?' };
194
+ document.getElementById('md').content = '### Markdown\\nRenders **bold**, \`code\`, lists.';
195
+ document.getElementById('reason').text = 'First I parse, then plan, then verify.';
196
+ document.getElementById('code').code = 'export const add = (a, b) => a + b;';
197
+ document.getElementById('cot').steps = [{ label: 'Understand' }, { label: 'Design' }, { label: 'Build' }];
198
+ document.getElementById('tool').tool = {
199
+ type: 'database_query', state: 'output-available',
200
+ input: { table: 'users', limit: 10 }, output: { rows: 10, ms: 42 },
201
+ };
202
+ </script>`;
203
+
204
+ export const Messages: Story = {
205
+ name: '02 · Messages',
206
+ render: () => {
207
+ let msgA!: HTMLElement, msgU!: HTMLElement, md!: HTMLElement, reason!: HTMLElement;
208
+ let cot!: HTMLElement, code!: HTMLElement, tool!: HTMLElement;
209
+ onMount(() => {
210
+ props(msgA, { message: assistantMessage });
211
+ props(msgU, { message: userMessage });
212
+ props(md, { content: '### Markdown\nRenders **bold**, _italic_, `code`, and lists:\n- one\n- two\n\n> and blockquotes.' });
213
+ props(reason, { text: 'First I parse the request, then I plan the steps, then I execute and verify.' });
214
+ attrs(reason, { label: 'Reasoning', streaming: true });
215
+ props(cot, { steps: cotSteps });
216
+ props(code, { code: 'export function add(a: number, b: number): number {\n return a + b;\n}' });
217
+ attrs(code, { language: 'ts' });
218
+ props(tool, { tool: { type: 'database_query', state: 'output-available', input: { table: 'users', limit: 10 }, output: { rows: 10, ms: 42 } } });
219
+ attrs(tool, { open: true });
220
+ });
221
+ return (
222
+ <Grid>
223
+ <Spec tag="kc-message" note='role="assistant" — reasoning + tool + attachment + actions'>
224
+ <kc-message ref={(e) => (msgA = e)} />
225
+ </Spec>
226
+ <Spec tag="kc-message" note='role="user"'>
227
+ <kc-message ref={(e) => (msgU = e)} />
228
+ </Spec>
229
+ <Spec tag="kc-markdown" note="token-themed markdown + fenced code">
230
+ <kc-markdown ref={(e) => (md = e)} />
231
+ </Spec>
232
+ <Spec tag="kc-reasoning" note="collapsible thinking; auto-opens while streaming">
233
+ <kc-reasoning ref={(e) => (reason = e)} />
234
+ </Spec>
235
+ <Spec tag="kc-chain-of-thought" note="step-by-step reasoning with connectors">
236
+ <kc-chain-of-thought ref={(e) => (cot = e)} />
237
+ </Spec>
238
+ <Spec tag="kc-code-block" note='language="ts" — highlighted, copyable'>
239
+ <kc-code-block ref={(e) => (code = e)} />
240
+ </Spec>
241
+ <Spec tag="kc-tool" note="open — input, output, state badge">
242
+ <kc-tool ref={(e) => (tool = e)} />
243
+ </Spec>
244
+ </Grid>
245
+ );
246
+ },
247
+ parameters: { docs: { source: { code: MESSAGES_SNIPPET, language: 'html' } } },
248
+ };
249
+
250
+ // ── 03 · Attachments & media ─────────────────────────────────────────────────
251
+
252
+ const MEDIA_SNIPPET = `<!-- One element, presentation chosen by attribute -->
253
+ <kc-attachments id="inline" variant="inline" hover-card></kc-attachments>
254
+ <kc-attachments id="grid" variant="grid" removable></kc-attachments>
255
+ <kc-image id="img" alt="demo" style="width:96px"></kc-image>
256
+ <kc-source href="https://kitn.dev" headline="kitn — the kit"
257
+ description="Composable chat UI." show-favicon></kc-source>
258
+ <kc-sources id="srcs"></kc-sources>
259
+
260
+ <script type="module">
261
+ import '@kitnai/chat/elements';
262
+ const items = [
263
+ { id: '1', type: 'file', filename: 'architecture.png', mediaType: 'image/png', url: '…' },
264
+ { id: '2', type: 'file', filename: 'spec.pdf', mediaType: 'application/pdf' },
265
+ ];
266
+ document.getElementById('inline').items = items;
267
+ const grid = document.getElementById('grid');
268
+ grid.items = items;
269
+ grid.addEventListener('remove', (e) => (grid.items = grid.items.filter((x) => x.id !== e.detail.id)));
270
+ document.getElementById('img').base64 = '…'; // pair with media-type
271
+ document.getElementById('srcs').sources = [
272
+ { href: 'https://kitn.dev', title: 'kitn', description: '…', showFavicon: true },
273
+ ];
274
+ </script>`;
275
+
276
+ export const AttachmentsAndMedia: Story = {
277
+ name: '03 · Attachments & media',
278
+ render: () => {
279
+ let inline!: HTMLElement, grid!: HTMLElement, img!: HTMLElement, src!: HTMLElement, srcs!: HTMLElement;
280
+ onMount(() => {
281
+ props(inline, { items: attachments });
282
+ attrs(inline, { variant: 'inline', 'hover-card': true });
283
+ props(grid, { items: attachments });
284
+ attrs(grid, { variant: 'grid', removable: true });
285
+ grid.addEventListener('remove', (e) => {
286
+ const id = (e as CustomEvent).detail.id;
287
+ (grid as AnyEl).items = (attachments as { id: string }[]).filter((x) => x.id !== id);
288
+ });
289
+ props(img, {
290
+ base64: btoa(unescape(encodeURIComponent(
291
+ '<svg xmlns="http://www.w3.org/2000/svg" width="96" height="96"><rect width="96" height="96" rx="16" fill="#7c3aed"/><text x="48" y="62" font-size="44" text-anchor="middle" fill="white">★</text></svg>'))),
292
+ });
293
+ attrs(img, { alt: 'demo', 'media-type': 'image/svg+xml' });
294
+ attrs(src, { href: 'https://kitn.dev', headline: 'kitn — the kit', description: 'Composable SolidJS + web-component chat UI.', 'show-favicon': true });
295
+ props(srcs, { sources });
296
+ });
297
+ return (
298
+ <Grid>
299
+ <Spec tag="kc-attachments" note='variant="inline" hover-card'>
300
+ <kc-attachments ref={(e) => (inline = e)} />
301
+ </Spec>
302
+ <Spec tag="kc-attachments" note='variant="grid" removable'>
303
+ <kc-attachments ref={(e) => (grid = e)} />
304
+ </Spec>
305
+ <Spec tag="kc-image" note="base64 / byte-array image with skeleton">
306
+ <kc-image ref={(e) => (img = e)} style={{ width: '96px' }} />
307
+ </Spec>
308
+ <Spec tag="kc-source" note="show-favicon — citation with hover preview">
309
+ <kc-source ref={(e) => (src = e)} />
310
+ </Spec>
311
+ <Spec tag="kc-sources" note="wrapped row of citations">
312
+ <kc-sources ref={(e) => (srcs = e)} />
313
+ </Spec>
314
+ </Grid>
315
+ );
316
+ },
317
+ parameters: { docs: { source: { code: MEDIA_SNIPPET, language: 'html' } } },
318
+ };
319
+
320
+ // ── 04 · Composer ────────────────────────────────────────────────────────────
321
+
322
+ const COMPOSER_SNIPPET = `<!-- Input affordances you can place anywhere -->
323
+ <kc-suggestions id="suggs"></kc-suggestions>
324
+ <kc-file-upload></kc-file-upload>
325
+ <kc-voice-input id="voice"></kc-voice-input>
326
+ <kc-thinking-bar text="Thinking…" stoppable></kc-thinking-bar>
327
+
328
+ <script type="module">
329
+ import '@kitnai/chat/elements';
330
+ const suggs = document.getElementById('suggs');
331
+ suggs.suggestions = ['Explain the architecture', 'Show me a code example'];
332
+ suggs.addEventListener('select', (e) => console.log('select', e.detail.value));
333
+
334
+ const voice = document.getElementById('voice');
335
+ voice.transcribe = async () => 'transcribed text'; // your STT here
336
+ voice.addEventListener('transcription', (e) => console.log(e.detail.text));
337
+ </script>`;
338
+
339
+ export const Composer: Story = {
340
+ name: '04 · Composer',
341
+ render: () => {
342
+ let suggs!: HTMLElement, voice!: HTMLElement, think!: HTMLElement;
343
+ onMount(() => {
344
+ props(suggs, { suggestions: ['Explain the architecture', 'Show me a code example', "What's deferred?"] });
345
+ props(voice, { transcribe: async () => { await new Promise((r) => setTimeout(r, 400)); return 'transcribed text'; } });
346
+ attrs(think, { text: 'Thinking…', stoppable: true });
347
+ });
348
+ return (
349
+ <Grid>
350
+ <Spec tag="kc-suggestions" note="suggestion chips; click fires select">
351
+ <kc-suggestions ref={(e) => (suggs = e)} />
352
+ </Spec>
353
+ <Spec tag="kc-file-upload" note="click / drag-drop dropzone">
354
+ <kc-file-upload />
355
+ </Spec>
356
+ <Spec tag="kc-voice-input · kc-thinking-bar" note="mic capture + shimmering thinking bar">
357
+ <div style={{ display: 'flex', gap: '8px', 'align-items': 'center' }}>
358
+ <kc-voice-input ref={(e) => (voice = e)} />
359
+ <kc-thinking-bar ref={(e) => (think = e)} style={{ flex: '1' }} />
360
+ </div>
361
+ </Spec>
362
+ </Grid>
363
+ );
364
+ },
365
+ parameters: { docs: { source: { code: COMPOSER_SNIPPET, language: 'html' } } },
366
+ };
367
+
368
+ // ── 05 · Header & meta ───────────────────────────────────────────────────────
369
+
370
+ const META_SNIPPET = `<!-- The small pieces around a conversation -->
371
+ <kc-model-switcher id="models"></kc-model-switcher>
372
+ <kc-context id="ctx"></kc-context>
373
+ <kc-scope-picker id="scope"></kc-scope-picker>
374
+ <kc-checkpoint label="Checkpoint" tooltip="Restore"></kc-checkpoint>
375
+ <kc-skills id="skills"></kc-skills>
376
+ <kc-feedback-bar bar-title="Was this helpful?"></kc-feedback-bar>
377
+
378
+ <script type="module">
379
+ import '@kitnai/chat/elements';
380
+ const ms = document.getElementById('models');
381
+ ms.models = [{ id: 'opus', name: 'Claude Opus', provider: 'Anthropic' }];
382
+ ms.currentModel = 'opus';
383
+ ms.addEventListener('modelchange', (e) => (ms.currentModel = e.detail.modelId));
384
+
385
+ document.getElementById('ctx').context = { usedTokens: 48200, maxTokens: 200000 };
386
+ const scope = document.getElementById('scope');
387
+ scope.availableAuthors = ['Rob', 'Alex'];
388
+ scope.availableTags = ['design', 'api'];
389
+ document.getElementById('skills').skills = [{ id: 's1', name: 'web-search' }];
390
+ </script>`;
391
+
392
+ export const HeaderAndMeta: Story = {
393
+ name: '05 · Header & meta',
394
+ render: () => {
395
+ let ms!: HTMLElement, ctx!: HTMLElement, scope!: HTMLElement, cp!: HTMLElement, skills!: HTMLElement, fb!: HTMLElement;
396
+ onMount(() => {
397
+ props(ms, { models, currentModel: 'opus' });
398
+ ms.addEventListener('modelchange', (e) => ((ms as AnyEl).currentModel = (e as CustomEvent).detail.modelId));
399
+ props(ctx, { context });
400
+ props(scope, { availableAuthors: ['Rob', 'Alex'], availableTags: ['design', 'api'] });
401
+ attrs(cp, { label: 'Checkpoint', tooltip: 'Restore' });
402
+ props(skills, { skills: [{ id: 's1', name: 'web-search' }, { id: 's2', name: 'code' }] });
403
+ attrs(fb, { 'bar-title': 'Was this helpful?' });
404
+ });
405
+ return (
406
+ <Grid>
407
+ <Spec tag="kc-model-switcher" note="model dropdown; emits modelchange">
408
+ <kc-model-switcher ref={(e) => (ms = e)} />
409
+ </Spec>
410
+ <Spec tag="kc-context" note="token-usage meter with breakdown">
411
+ <kc-context ref={(e) => (ctx = e)} />
412
+ </Spec>
413
+ <Spec tag="kc-scope-picker" note="scope a chat by author or tag">
414
+ <kc-scope-picker ref={(e) => (scope = e)} />
415
+ </Spec>
416
+ <Spec tag="kc-checkpoint · kc-skills" note="bookmark button + active-skill badges">
417
+ <div style={{ display: 'flex', gap: '8px', 'align-items': 'center' }}>
418
+ <kc-checkpoint ref={(e) => (cp = e)} />
419
+ <kc-skills ref={(e) => (skills = e)} />
420
+ </div>
421
+ </Spec>
422
+ <Spec tag="kc-feedback-bar" note="inline thumbs up/down banner">
423
+ <kc-feedback-bar ref={(e) => (fb = e)} />
424
+ </Spec>
425
+ </Grid>
426
+ );
427
+ },
428
+ parameters: { docs: { source: { code: META_SNIPPET, language: 'html' } } },
429
+ };
430
+
431
+ // ── 06 · Status & motion ─────────────────────────────────────────────────────
432
+
433
+ const STATUS_SNIPPET = `<!-- Loaders, streaming text, and empty states -->
434
+ <kc-loader variant="circular"></kc-loader>
435
+ <kc-loader variant="dots"></kc-loader>
436
+ <kc-text-shimmer text="Generating response…"></kc-text-shimmer>
437
+ <kc-response-stream id="stream" speed="30"></kc-response-stream>
438
+ <kc-empty empty-title="No conversations yet" description="Start chatting to see them here.">
439
+ <span slot="media">✦</span>
440
+ </kc-empty>
441
+
442
+ <script type="module">
443
+ import '@kitnai/chat/elements';
444
+ const stream = document.getElementById('stream');
445
+ stream.text = 'This text reveals with a typewriter animation, character by character.';
446
+ stream.addEventListener('complete', () => console.log('done'));
447
+ </script>`;
448
+
449
+ export const StatusAndMotion: Story = {
450
+ name: '06 · Status & motion',
451
+ render: () => {
452
+ let l1!: HTMLElement, l2!: HTMLElement, l3!: HTMLElement, l4!: HTMLElement, l5!: HTMLElement;
453
+ let shimmer!: HTMLElement, stream!: HTMLElement, empty!: HTMLElement;
454
+ onMount(() => {
455
+ attrs(l1, { variant: 'circular' });
456
+ attrs(l2, { variant: 'dots' });
457
+ attrs(l3, { variant: 'wave' });
458
+ attrs(l4, { variant: 'bars' });
459
+ attrs(l5, { variant: 'pulse-dot' });
460
+ attrs(shimmer, { text: 'Generating response…' });
461
+ attrs(stream, { speed: '30' });
462
+ props(stream, { text: "This text reveals with a typewriter animation, streamed character by character — exactly how you'd render a live assistant reply." });
463
+ attrs(empty, { 'empty-title': 'No conversations yet', description: 'Start chatting to see them here.' });
464
+ });
465
+ return (
466
+ <Grid>
467
+ <Spec tag="kc-loader" note="twelve loader styles">
468
+ <div style={{ display: 'flex', gap: '24px', 'align-items': 'center', 'flex-wrap': 'wrap' }}>
469
+ <kc-loader ref={(e) => (l1 = e)} />
470
+ <kc-loader ref={(e) => (l2 = e)} />
471
+ <kc-loader ref={(e) => (l3 = e)} />
472
+ <kc-loader ref={(e) => (l4 = e)} />
473
+ <kc-loader ref={(e) => (l5 = e)} />
474
+ </div>
475
+ </Spec>
476
+ <Spec tag="kc-text-shimmer" note="animated shimmering text">
477
+ <kc-text-shimmer ref={(e) => (shimmer = e)} />
478
+ </Spec>
479
+ <Spec tag="kc-response-stream" note='mode="typewriter" — emits complete'>
480
+ <kc-response-stream ref={(e) => (stream = e)} />
481
+ </Spec>
482
+ <Spec tag="kc-empty" note="empty-state layout — media & default slots">
483
+ <kc-empty ref={(e) => (empty = e)}>
484
+ <span slot="media">✦</span>
485
+ </kc-empty>
486
+ </Spec>
487
+ </Grid>
488
+ );
489
+ },
490
+ parameters: { docs: { source: { code: STATUS_SNIPPET, language: 'html' } } },
491
+ };