@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,150 +0,0 @@
1
- import type { Meta, StoryObj } from 'storybook-solidjs-vite';
2
- import { CodeBlock, CodeBlockCode, CodeBlockGroup } from './code-block';
3
- import { Button } from '../ui/button';
4
- import { componentDescription } from '../stories/docs/element-controls';
5
-
6
- const tsCode = `interface User {
7
- id: string;
8
- name: string;
9
- email: string;
10
- }
11
-
12
- function greet(user: User): string {
13
- return \`Hello, \${user.name}!\`;
14
- }`;
15
-
16
- const pythonCode = `def fibonacci(n: int) -> list[int]:
17
- """Generate fibonacci sequence up to n numbers."""
18
- if n <= 0:
19
- return []
20
- sequence = [0, 1]
21
- while len(sequence) < n:
22
- sequence.append(sequence[-1] + sequence[-2])
23
- return sequence[:n]
24
-
25
- print(fibonacci(10))`;
26
-
27
- const cssCode = `:root {
28
- --primary: hsl(240 5.9% 10%);
29
- --background: hsl(0 0% 100%);
30
- }
31
-
32
- .button {
33
- background: var(--color-primary);
34
- color: white;
35
- border-radius: 0.5rem;
36
- padding: 0.5rem 1rem;
37
- }`;
38
-
39
- /**
40
- * Story for the compound `CodeBlock` family. The root `CodeBlock` is a bordered
41
- * card container; `CodeBlockCode` does the (on-demand, Shiki) syntax
42
- * highlighting; `CodeBlockGroup` is a flex header/footer row. The controllable
43
- * props live on `CodeBlockCode`, so `Playground` drives that piece directly.
44
- */
45
- const meta = {
46
- title: 'Solid (Advanced)/Elements/CodeBlock',
47
- component: CodeBlockCode,
48
- tags: ['autodocs'],
49
- parameters: {
50
- layout: 'padded',
51
- docs: {
52
- description: componentDescription([
53
- 'A bordered code card with optional syntax highlighting. `CodeBlock` is the container, `CodeBlockCode` renders the (Shiki-)highlighted source, and `CodeBlockGroup` is a flex row for a header/footer (filename + copy button).',
54
- '**When to use:** to display code snippets in chat messages, documentation, or anywhere fenced code appears — typically emitted by the Markdown renderer for ``` blocks.',
55
- '**How to use:** wrap one or more children in `<CodeBlock>`. Pass the source string and a `language` to `<CodeBlockCode>`; optionally override the `theme`. Add a `<CodeBlockGroup>` for a filename row and copy action.',
56
- '**Placement:** inside assistant message content, README/docs panes, and tool-output views.',
57
- ]),
58
- controls: { exclude: ['use:eventListener'] },
59
- },
60
- },
61
- argTypes: {
62
- code: {
63
- control: 'text',
64
- description: 'The source code string to render.',
65
- },
66
- language: {
67
- control: 'text',
68
- description: 'Language id for syntax highlighting (e.g. `typescript`, `python`, `css`).',
69
- table: { defaultValue: { summary: 'tsx' } },
70
- },
71
- theme: {
72
- control: 'text',
73
- description: 'Shiki theme id. Falls back to the active ChatConfig `codeTheme`.',
74
- },
75
- },
76
- args: {
77
- code: tsCode,
78
- language: 'typescript',
79
- },
80
- render: (args) => (
81
- <div class="max-w-lg">
82
- <CodeBlock>
83
- <CodeBlockCode {...args} />
84
- </CodeBlock>
85
- </div>
86
- ),
87
- } satisfies Meta<typeof CodeBlockCode>;
88
-
89
- export default meta;
90
- type Story = StoryObj<typeof meta>;
91
-
92
- const IMPORT = `import { CodeBlock, CodeBlockCode, CodeBlockGroup } from '@kitn.ai/ui';`;
93
- const src = (code: string) => ({
94
- parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
95
- });
96
-
97
- /** Interactive playground — edit the code, language, or theme via controls. */
98
- export const Playground: Story = {
99
- ...src(`<CodeBlock>
100
- <CodeBlockCode code={tsCode} language="typescript" />
101
- </CodeBlock>`),
102
- };
103
-
104
- export const TypeScript: Story = {
105
- args: { code: tsCode, language: 'typescript' },
106
- ...src(`<CodeBlock>
107
- <CodeBlockCode code={tsCode} language="typescript" />
108
- </CodeBlock>`),
109
- };
110
-
111
- export const Python: Story = {
112
- args: { code: pythonCode, language: 'python' },
113
- ...src(`<CodeBlock>
114
- <CodeBlockCode code={pythonCode} language="python" />
115
- </CodeBlock>`),
116
- };
117
-
118
- export const CSS: Story = {
119
- args: { code: cssCode, language: 'css' },
120
- ...src(`<CodeBlock>
121
- <CodeBlockCode code={cssCode} language="css" />
122
- </CodeBlock>`),
123
- };
124
-
125
- /** A header row (`CodeBlockGroup`) with a filename and a copy button — showcase. */
126
- export const WithHeader: Story = {
127
- render: () => (
128
- <div class="max-w-lg">
129
- <CodeBlock>
130
- <CodeBlockGroup class="border-b border-border px-4 py-2">
131
- <span class="text-xs text-muted-foreground font-mono">user.ts</span>
132
- <Button variant="ghost" size="icon-sm" aria-label="Copy code">
133
- <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
134
- <rect x="9" y="9" width="13" height="13" rx="2" ry="2" />
135
- <path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1" />
136
- </svg>
137
- </Button>
138
- </CodeBlockGroup>
139
- <CodeBlockCode code={tsCode} language="typescript" />
140
- </CodeBlock>
141
- </div>
142
- ),
143
- ...src(`<CodeBlock>
144
- <CodeBlockGroup class="border-b border-border px-4 py-2">
145
- <span class="text-xs text-muted-foreground font-mono">user.ts</span>
146
- <Button variant="ghost" size="icon-sm">{/* copy icon */}</Button>
147
- </CodeBlockGroup>
148
- <CodeBlockCode code={tsCode} language="typescript" />
149
- </CodeBlock>`),
150
- };
@@ -1,74 +0,0 @@
1
- import type { Meta, StoryObj } from 'storybook-solidjs-vite';
2
- import { createSignal } from 'solid-js';
3
- import { ConfirmCard, type ConfirmCardData } from './confirm-card';
4
- import { componentDescription } from '../stories/docs/element-controls';
5
- import type { CardEvent, CardHost, CardContext } from '../primitives/card-contract';
6
-
7
- const ctx: CardContext = { theme: { mode: 'light' }, locale: 'en' };
8
-
9
- /** Renders the Solid <ConfirmCard> with a capturing `host`, logging emitted events. */
10
- function Demo(props: { def: ConfirmCardData; heading?: string; cardId: string }) {
11
- const [log, setLog] = createSignal<CardEvent[]>([]);
12
- const host: CardHost = { context: () => ctx, emit: (e) => setLog((p) => [...p, e]) };
13
- return (
14
- <div style={{ 'max-width': '460px', display: 'flex', 'flex-direction': 'column', gap: '12px' }}>
15
- <ConfirmCard host={host} data={props.def} heading={props.heading} cardId={props.cardId} />
16
- <pre
17
- style={{
18
- margin: 0,
19
- 'max-height': '180px',
20
- overflow: 'auto',
21
- background: 'var(--color-muted, #f4f4f5)',
22
- 'border-radius': '8px',
23
- padding: '8px',
24
- 'font-size': '12px',
25
- }}
26
- >
27
- {log().length === 0 ? '// emitted CardEvents appear here' : JSON.stringify(log(), null, 2)}
28
- </pre>
29
- </div>
30
- );
31
- }
32
-
33
- const APPROVE: ConfirmCardData = {
34
- body: 'This will apply 3 pending migrations to production. This cannot be undone.',
35
- tone: 'warning',
36
- actions: [
37
- { id: 'approve', label: 'Run migration', style: 'primary', default: true },
38
- { id: 'reject', label: 'Cancel' },
39
- ],
40
- };
41
-
42
- const DESTRUCTIVE: ConfirmCardData = {
43
- body: 'Permanently delete 12 files? This cannot be undone.',
44
- tone: 'danger',
45
- actions: [
46
- { id: 'delete', label: 'Delete files', style: 'destructive', default: true },
47
- { id: 'cancel', label: 'Keep them' },
48
- ],
49
- };
50
-
51
- const meta = {
52
- title: 'Solid (Advanced)/Elements/ConfirmCard',
53
- component: ConfirmCard,
54
- tags: ['autodocs'],
55
- parameters: {
56
- layout: 'padded',
57
- docs: {
58
- description: componentDescription([
59
- 'The SolidJS layer behind `<kai-confirm>`. Pass a `host` (a `CardHost`) to receive the emitted `CardEvent`s directly (the native-host path), or wrap in a `CardProvider`. Activating an action emits the `action` verb and resolves the card.',
60
- ]),
61
- },
62
- },
63
- } satisfies Meta<typeof ConfirmCard>;
64
-
65
- export default meta;
66
- type Story = StoryObj<typeof ConfirmCard>;
67
-
68
- export const ApproveReject: Story = {
69
- render: () => <Demo def={APPROVE} heading="Run database migration?" cardId="card-approve" />,
70
- };
71
-
72
- export const Destructive: Story = {
73
- render: () => <Demo def={DESTRUCTIVE} heading="Delete files?" cardId="card-delete" />,
74
- };
@@ -1,229 +0,0 @@
1
- import type { Meta, StoryObj } from 'storybook-solidjs-vite';
2
- import {
3
- Context,
4
- ContextTrigger,
5
- ContextContent,
6
- ContextContentHeader,
7
- ContextContentBody,
8
- ContextContentFooter,
9
- ContextInputUsage,
10
- ContextOutputUsage,
11
- ContextReasoningUsage,
12
- ContextCacheUsage,
13
- } from './context';
14
- import { componentDescription } from '../stories/docs/element-controls';
15
-
16
- /**
17
- * Story for the compound `Context` family. `Context` is the root provider that
18
- * holds the token-usage values; the trigger/content/usage-row subcomponents read
19
- * from it. The controllable props all live on the `Context` root, so `Playground`
20
- * drives the root and composes a full hover-card breakdown.
21
- */
22
- const meta = {
23
- title: 'Solid (Advanced)/Elements/Context',
24
- component: Context,
25
- tags: ['autodocs'],
26
- parameters: {
27
- layout: 'padded',
28
- docs: {
29
- description: componentDescription([
30
- 'A model context-window usage indicator: a hover-card trigger showing the used-percent ring, with a popover breaking down token usage (input / output / reasoning / cache) and estimated cost.',
31
- '**When to use:** to surface how much of a model\'s context window a conversation has consumed and roughly what it costs — near the prompt input or in a chat header.',
32
- '**How to use:** wrap the composition in `<Context>` and pass `usedTokens` / `maxTokens` (plus optional `inputTokens`, `outputTokens`, `reasoningTokens`, `cacheTokens`, `estimatedCost`). Compose `ContextTrigger`, `ContextContent` (with `Header`/`Body`/`Footer`), and the usage rows.',
33
- '**Placement:** chat toolbars, prompt-input action bars, and conversation headers.',
34
- ]),
35
- controls: { exclude: ['use:eventListener'] },
36
- },
37
- },
38
- argTypes: {
39
- usedTokens: {
40
- control: 'number',
41
- description: 'Tokens consumed so far. Drives the ring fill and progress bar.',
42
- },
43
- maxTokens: {
44
- control: 'number',
45
- description: 'Total context window size.',
46
- },
47
- inputTokens: {
48
- control: 'number',
49
- description: 'Prompt/input tokens (shown by `ContextInputUsage`).',
50
- },
51
- outputTokens: {
52
- control: 'number',
53
- description: 'Generated/output tokens (shown by `ContextOutputUsage`).',
54
- },
55
- reasoningTokens: {
56
- control: 'number',
57
- description: 'Reasoning tokens (shown by `ContextReasoningUsage`).',
58
- },
59
- cacheTokens: {
60
- control: 'number',
61
- description: 'Cached tokens (shown by `ContextCacheUsage`).',
62
- },
63
- estimatedCost: {
64
- control: 'number',
65
- description: 'Estimated cost in USD (shown by `ContextContentFooter`).',
66
- },
67
- warnThreshold: {
68
- control: 'number',
69
- description: 'Fraction (0–1) above which the bar turns yellow. Default `0.7`.',
70
- },
71
- dangerThreshold: {
72
- control: 'number',
73
- description: 'Fraction (0–1) above which the bar turns red. Default `0.9`.',
74
- },
75
- },
76
- args: {
77
- usedTokens: 85000,
78
- maxTokens: 128000,
79
- inputTokens: 60000,
80
- outputTokens: 15000,
81
- reasoningTokens: 8000,
82
- cacheTokens: 2000,
83
- estimatedCost: 0.45,
84
- },
85
- render: (args) => (
86
- <Context {...args}>
87
- <ContextTrigger />
88
- <ContextContent>
89
- <ContextContentHeader />
90
- <ContextContentBody>
91
- <div class="space-y-1">
92
- <ContextInputUsage />
93
- <ContextOutputUsage />
94
- <ContextReasoningUsage />
95
- <ContextCacheUsage />
96
- </div>
97
- </ContextContentBody>
98
- <ContextContentFooter />
99
- </ContextContent>
100
- </Context>
101
- ),
102
- } satisfies Meta<typeof Context>;
103
-
104
- export default meta;
105
- type Story = StoryObj<typeof meta>;
106
-
107
- const IMPORT = `import {
108
- Context, ContextTrigger, ContextContent, ContextContentHeader,
109
- ContextContentBody, ContextContentFooter,
110
- ContextInputUsage, ContextOutputUsage, ContextReasoningUsage, ContextCacheUsage,
111
- } from '@kitn.ai/ui';`;
112
- const src = (code: string) => ({
113
- parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
114
- });
115
-
116
- const usage = `<Context usedTokens={85000} maxTokens={128000} inputTokens={60000} outputTokens={15000} reasoningTokens={8000} cacheTokens={2000} estimatedCost={0.45}>
117
- <ContextTrigger />
118
- <ContextContent>
119
- <ContextContentHeader />
120
- <ContextContentBody>
121
- <div class="space-y-1">
122
- <ContextInputUsage />
123
- <ContextOutputUsage />
124
- <ContextReasoningUsage />
125
- <ContextCacheUsage />
126
- </div>
127
- </ContextContentBody>
128
- <ContextContentFooter />
129
- </ContextContent>
130
- </Context>`;
131
-
132
- /** Interactive playground — tweak token counts to watch the ring, bar color, and breakdown update. */
133
- export const Playground: Story = {
134
- ...src(usage),
135
- };
136
-
137
- export const LowUsage: Story = {
138
- args: {
139
- usedTokens: 12000,
140
- maxTokens: 128000,
141
- inputTokens: 8000,
142
- outputTokens: 4000,
143
- reasoningTokens: undefined,
144
- cacheTokens: undefined,
145
- estimatedCost: 0.02,
146
- },
147
- ...src(usage),
148
- };
149
-
150
- export const MediumUsage: Story = {
151
- args: {
152
- usedTokens: 85000,
153
- maxTokens: 128000,
154
- inputTokens: 60000,
155
- outputTokens: 15000,
156
- reasoningTokens: 8000,
157
- cacheTokens: 2000,
158
- estimatedCost: 0.45,
159
- },
160
- ...src(usage),
161
- };
162
-
163
- export const HighUsage: Story = {
164
- args: {
165
- usedTokens: 122000,
166
- maxTokens: 128000,
167
- inputTokens: 90000,
168
- outputTokens: 22000,
169
- reasoningTokens: 10000,
170
- cacheTokens: undefined,
171
- estimatedCost: 1.85,
172
- },
173
- ...src(usage),
174
- };
175
-
176
- export const WithCost: Story = {
177
- args: {
178
- usedTokens: 50000,
179
- maxTokens: 200000,
180
- inputTokens: 35000,
181
- outputTokens: 10000,
182
- reasoningTokens: 5000,
183
- cacheTokens: undefined,
184
- estimatedCost: 0.32,
185
- },
186
- ...src(usage),
187
- };
188
-
189
- const customThresholdUsage = `<Context
190
- usedTokens={110000}
191
- maxTokens={200000}
192
- inputTokens={70000}
193
- outputTokens={40000}
194
- estimatedCost={0.65}
195
- warnThreshold={0.5}
196
- dangerThreshold={0.75}
197
- >
198
- <ContextTrigger />
199
- <ContextContent>
200
- <ContextContentHeader />
201
- <ContextContentBody>
202
- <div class="space-y-1">
203
- <ContextInputUsage />
204
- <ContextOutputUsage />
205
- </div>
206
- </ContextContentBody>
207
- <ContextContentFooter />
208
- </ContextContent>
209
- </Context>`;
210
-
211
- /**
212
- * Custom thresholds — `warnThreshold=0.5` / `dangerThreshold=0.75` so the bar
213
- * turns yellow at 50% and red at 75%. At 55% (110 000 / 200 000) the bar renders
214
- * yellow even though the defaults would show green at this level.
215
- */
216
- export const CustomThresholds: Story = {
217
- args: {
218
- usedTokens: 110000,
219
- maxTokens: 200000,
220
- inputTokens: 70000,
221
- outputTokens: 40000,
222
- reasoningTokens: undefined,
223
- cacheTokens: undefined,
224
- estimatedCost: 0.65,
225
- warnThreshold: 0.5,
226
- dangerThreshold: 0.75,
227
- },
228
- ...src(customThresholdUsage),
229
- };
@@ -1,133 +0,0 @@
1
- import { describe, it, expect, afterEach, beforeEach, vi } from 'vitest';
2
- import '@testing-library/jest-dom/vitest';
3
- import { render, cleanup, fireEvent, screen } from '@solidjs/testing-library';
4
- import {
5
- Context,
6
- ContextTrigger,
7
- ContextContent,
8
- ContextContentHeader,
9
- ContextContentBody,
10
- ContextContentFooter,
11
- computeSeverity,
12
- DEFAULT_WARN_THRESHOLD,
13
- DEFAULT_DANGER_THRESHOLD,
14
- } from './context';
15
-
16
- // jsdom does not implement PointerEvent — shim it so fireEvent.pointerEnter works.
17
- if (typeof (globalThis as unknown as Record<string, unknown>).PointerEvent === 'undefined') {
18
- (globalThis as unknown as Record<string, unknown>).PointerEvent = class PointerEvent extends MouseEvent {
19
- constructor(type: string, params?: PointerEventInit) { super(type, params); }
20
- };
21
- }
22
-
23
- beforeEach(() => vi.useFakeTimers());
24
- afterEach(() => {
25
- vi.useRealTimers();
26
- cleanup();
27
- });
28
-
29
- // ---------------------------------------------------------------------------
30
- // computeSeverity — pure function unit tests
31
- // ---------------------------------------------------------------------------
32
-
33
- describe('computeSeverity', () => {
34
- it('returns ok below the warn threshold (defaults)', () => {
35
- expect(computeSeverity(0)).toBe('ok');
36
- expect(computeSeverity(0.5)).toBe('ok');
37
- expect(computeSeverity(DEFAULT_WARN_THRESHOLD)).toBe('ok'); // exactly at threshold → still ok
38
- });
39
-
40
- it('returns warn when usage exceeds the warn threshold but not the danger threshold', () => {
41
- expect(computeSeverity(0.71)).toBe('warn');
42
- expect(computeSeverity(DEFAULT_WARN_THRESHOLD + 0.001)).toBe('warn');
43
- expect(computeSeverity(DEFAULT_DANGER_THRESHOLD)).toBe('warn'); // exactly at danger threshold → still warn
44
- });
45
-
46
- it('returns danger when usage exceeds the danger threshold', () => {
47
- expect(computeSeverity(0.91)).toBe('danger');
48
- expect(computeSeverity(1.0)).toBe('danger');
49
- });
50
-
51
- it('respects custom warnThreshold', () => {
52
- expect(computeSeverity(0.49, 0.5, 0.9)).toBe('ok');
53
- expect(computeSeverity(0.51, 0.5, 0.9)).toBe('warn');
54
- expect(computeSeverity(0.91, 0.5, 0.9)).toBe('danger');
55
- });
56
-
57
- it('respects custom dangerThreshold', () => {
58
- expect(computeSeverity(0.49, 0.5, 0.75)).toBe('ok');
59
- expect(computeSeverity(0.6, 0.5, 0.75)).toBe('warn');
60
- expect(computeSeverity(0.76, 0.5, 0.75)).toBe('danger');
61
- });
62
- });
63
-
64
- // ---------------------------------------------------------------------------
65
- // Context component — color class flips at configured thresholds
66
- //
67
- // HoverCardRoot uses openDelay={0} inside Context, so after a pointerEnter
68
- // the card opens immediately; we advance fake timers by 0 to flush it.
69
- // ---------------------------------------------------------------------------
70
-
71
- function FullMeter(props: {
72
- usedTokens: number;
73
- maxTokens: number;
74
- warnThreshold?: number;
75
- dangerThreshold?: number;
76
- }) {
77
- return (
78
- <Context {...props}>
79
- <ContextTrigger />
80
- <ContextContent>
81
- <ContextContentHeader />
82
- <ContextContentBody />
83
- <ContextContentFooter />
84
- </ContextContent>
85
- </Context>
86
- );
87
- }
88
-
89
- /** Open the hover card so ContextContentHeader is in the DOM. */
90
- function openCard() {
91
- // ContextTrigger renders HoverCardTrigger; the host wrapper is the parent of the button.
92
- const btn = screen.getByRole('button');
93
- fireEvent.pointerEnter(btn.parentElement!);
94
- vi.advanceTimersByTime(0); // openDelay=0 → card opens immediately
95
- }
96
-
97
- describe('Context color thresholds', () => {
98
- it('renders bg-primary bar below default warn threshold (< 70%)', () => {
99
- render(() => <FullMeter usedTokens={69000} maxTokens={100000} />);
100
- openCard();
101
- expect(document.querySelector('.bg-primary')).toBeInTheDocument();
102
- });
103
-
104
- it('renders bg-yellow-400 bar between default warn (70%) and danger (90%) thresholds', () => {
105
- render(() => <FullMeter usedTokens={80000} maxTokens={100000} />);
106
- openCard();
107
- expect(document.querySelector('.bg-yellow-400')).toBeInTheDocument();
108
- });
109
-
110
- it('renders bg-red-400 bar above default danger threshold (> 90%)', () => {
111
- render(() => <FullMeter usedTokens={91000} maxTokens={100000} />);
112
- openCard();
113
- expect(document.querySelector('.bg-red-400')).toBeInTheDocument();
114
- });
115
-
116
- it('flips to warn colour at a custom warnThreshold of 0.5', () => {
117
- render(() => <FullMeter usedTokens={51000} maxTokens={100000} warnThreshold={0.5} dangerThreshold={0.9} />);
118
- openCard();
119
- expect(document.querySelector('.bg-yellow-400')).toBeInTheDocument();
120
- });
121
-
122
- it('flips to danger colour at custom thresholds (warn 0.5, danger 0.75)', () => {
123
- render(() => <FullMeter usedTokens={76000} maxTokens={100000} warnThreshold={0.5} dangerThreshold={0.75} />);
124
- openCard();
125
- expect(document.querySelector('.bg-red-400')).toBeInTheDocument();
126
- });
127
-
128
- it('stays green at 50% when custom warnThreshold is 0.6', () => {
129
- render(() => <FullMeter usedTokens={50000} maxTokens={100000} warnThreshold={0.6} />);
130
- openCard();
131
- expect(document.querySelector('.bg-primary')).toBeInTheDocument();
132
- });
133
- });