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