@kitn.ai/ui 0.14.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.
- package/LICENSE +21 -0
- package/README.md +394 -0
- package/dist/bash-InADTalH.js +1 -0
- package/dist/core-AYMC6_lb.js +12 -0
- package/dist/css-M7EaDHN_.js +1 -0
- package/dist/custom-elements.json +4739 -0
- package/dist/engine-javascript-vq0WuIJl.js +141 -0
- package/dist/github-dark-dimmed-DUshB20C.js +1 -0
- package/dist/github-light-JYsPkUQd.js +1 -0
- package/dist/host-embed.d.ts +33 -0
- package/dist/html-CPZ3oZQ7.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/javascript-C25yR2R2.js +1 -0
- package/dist/json-DxJze_jm.js +1 -0
- package/dist/kitn-chat-provider.d.ts +2 -0
- package/dist/kitn-chat-provider.es.js +240 -0
- package/dist/kitn-chat.es.js +77 -0
- package/dist/llms/llms-full.txt +1018 -0
- package/dist/llms/llms.txt +104 -0
- package/dist/origin.d.ts +5 -0
- package/dist/provider-runtime.d.ts +27 -0
- package/dist/schemas/card-envelope.schema.json +14 -0
- package/dist/schemas/card-event.schema.json +12 -0
- package/dist/schemas/choice.schema.json +70 -0
- package/dist/schemas/confirm.schema.json +65 -0
- package/dist/schemas/embed.schema.json +65 -0
- package/dist/schemas/form.result.schema.json +7 -0
- package/dist/schemas/form.schema.json +33 -0
- package/dist/schemas/link.schema.json +56 -0
- package/dist/schemas/tasks.result.schema.json +16 -0
- package/dist/schemas/tasks.schema.json +78 -0
- package/dist/svelte--5p79yCD.js +1 -0
- package/dist/theme.tokens.css +176 -0
- package/dist/tsx-B8rCNbgL.js +1 -0
- package/dist/typescript-RycA9KXf.js +1 -0
- package/dist/validate.d.ts +4 -0
- package/dist/version.d.ts +4 -0
- package/dist/vue-BmIZj4XD.js +1 -0
- package/dist/wire.d.ts +53 -0
- package/frameworks/react/index.tsx +948 -0
- package/frameworks/react/runtime.tsx +94 -0
- package/llms-full.txt +1018 -0
- package/llms.txt +104 -0
- package/package.json +141 -0
- package/src/components/artifact.stories.tsx +138 -0
- package/src/components/artifact.tsx +743 -0
- package/src/components/attachments.stories.tsx +303 -0
- package/src/components/attachments.test.tsx +64 -0
- package/src/components/attachments.tsx +399 -0
- package/src/components/card-fallback.tsx +28 -0
- package/src/components/card-renderer.tsx +52 -0
- package/src/components/card.tsx +110 -0
- package/src/components/chain-of-thought.stories.tsx +211 -0
- package/src/components/chain-of-thought.tsx +139 -0
- package/src/components/chat-container.stories.tsx +187 -0
- package/src/components/chat-container.tsx +82 -0
- package/src/components/chat-scope-picker.tsx +47 -0
- package/src/components/chat-thread.test.tsx +58 -0
- package/src/components/chat-thread.tsx +249 -0
- package/src/components/checkpoint.stories.tsx +102 -0
- package/src/components/checkpoint.tsx +88 -0
- package/src/components/choice-card.tsx +569 -0
- package/src/components/code-block.stories.tsx +150 -0
- package/src/components/code-block.tsx +105 -0
- package/src/components/component-meta.json +3735 -0
- package/src/components/confirm-card.stories.tsx +74 -0
- package/src/components/confirm-card.tsx +315 -0
- package/src/components/context.stories.tsx +229 -0
- package/src/components/context.test.tsx +133 -0
- package/src/components/context.tsx +363 -0
- package/src/components/conversation-item.stories.tsx +125 -0
- package/src/components/conversation-item.tsx +16 -0
- package/src/components/conversation-list.stories.tsx +133 -0
- package/src/components/conversation-list.tsx +101 -0
- package/src/components/default-input.test.tsx +111 -0
- package/src/components/embed.tsx +196 -0
- package/src/components/empty.stories.tsx +434 -0
- package/src/components/empty.tsx +166 -0
- package/src/components/feedback-bar.stories.tsx +138 -0
- package/src/components/feedback-bar.test.tsx +103 -0
- package/src/components/feedback-bar.tsx +166 -0
- package/src/components/file-tree.stories.tsx +73 -0
- package/src/components/file-tree.tsx +383 -0
- package/src/components/file-upload.stories.tsx +156 -0
- package/src/components/file-upload.tsx +161 -0
- package/src/components/form-widgets.tsx +461 -0
- package/src/components/form.tsx +873 -0
- package/src/components/image.stories.tsx +89 -0
- package/src/components/image.tsx +67 -0
- package/src/components/link-preview.tsx +194 -0
- package/src/components/loader.stories.tsx +181 -0
- package/src/components/loader.tsx +333 -0
- package/src/components/markdown.stories.tsx +180 -0
- package/src/components/markdown.tsx +81 -0
- package/src/components/message-action-bar.test.tsx +128 -0
- package/src/components/message-narrow.stories.tsx +329 -0
- package/src/components/message-skills.stories.tsx +211 -0
- package/src/components/message-skills.tsx +36 -0
- package/src/components/message.stories.tsx +281 -0
- package/src/components/message.tsx +227 -0
- package/src/components/model-switcher.stories.tsx +123 -0
- package/src/components/model-switcher.test.tsx +65 -0
- package/src/components/model-switcher.tsx +87 -0
- package/src/components/prompt-input.stories.tsx +222 -0
- package/src/components/prompt-input.tsx +211 -0
- package/src/components/prompt-suggestion.stories.tsx +142 -0
- package/src/components/prompt-suggestion.tsx +115 -0
- package/src/components/reasoning.stories.tsx +140 -0
- package/src/components/reasoning.tsx +156 -0
- package/src/components/resizable.test.tsx +226 -0
- package/src/components/response-stream.tsx +103 -0
- package/src/components/scroll-button.stories.tsx +100 -0
- package/src/components/scroll-button.tsx +34 -0
- package/src/components/slash-command.stories.tsx +163 -0
- package/src/components/slash-command.tsx +232 -0
- package/src/components/source-list.test.tsx +152 -0
- package/src/components/source.stories.tsx +124 -0
- package/src/components/source.tsx +129 -0
- package/src/components/tasks-card.stories.tsx +78 -0
- package/src/components/tasks-card.tsx +432 -0
- package/src/components/text-shimmer.stories.tsx +87 -0
- package/src/components/text-shimmer.tsx +37 -0
- package/src/components/thinking-bar.stories.tsx +87 -0
- package/src/components/thinking-bar.tsx +50 -0
- package/src/components/tool.stories.tsx +153 -0
- package/src/components/tool.tsx +184 -0
- package/src/components/use-card-resolution.ts +28 -0
- package/src/components/voice-input.stories.tsx +83 -0
- package/src/components/voice-input.tsx +107 -0
- package/src/elements/artifact.stories.tsx +506 -0
- package/src/elements/artifact.tsx +137 -0
- package/src/elements/attachments.stories.tsx +190 -0
- package/src/elements/attachments.tsx +136 -0
- package/src/elements/card.stories.tsx +113 -0
- package/src/elements/card.tsx +40 -0
- package/src/elements/cards.stories.tsx +59 -0
- package/src/elements/cards.tsx +97 -0
- package/src/elements/catalog.stories.tsx +491 -0
- package/src/elements/chain-of-thought.declarative.test.tsx +153 -0
- package/src/elements/chain-of-thought.stories.tsx +113 -0
- package/src/elements/chain-of-thought.tsx +92 -0
- package/src/elements/chat-scope-picker.stories.tsx +73 -0
- package/src/elements/chat-scope-picker.tsx +36 -0
- package/src/elements/chat-types.ts +42 -0
- package/src/elements/chat-workspace.stories.tsx +288 -0
- package/src/elements/chat-workspace.tsx +161 -0
- package/src/elements/chat.stories.tsx +151 -0
- package/src/elements/chat.tsx +80 -0
- package/src/elements/checkpoint.stories.tsx +72 -0
- package/src/elements/checkpoint.tsx +47 -0
- package/src/elements/choice.stories.tsx +240 -0
- package/src/elements/choice.tsx +48 -0
- package/src/elements/code-block.stories.tsx +83 -0
- package/src/elements/code-block.tsx +42 -0
- package/src/elements/compiled.css +2 -0
- package/src/elements/composed-shell.stories.tsx +316 -0
- package/src/elements/confirm-card.stories.tsx +227 -0
- package/src/elements/confirm-card.tsx +51 -0
- package/src/elements/context-meter.stories.tsx +151 -0
- package/src/elements/context-meter.tsx +121 -0
- package/src/elements/conversation-list.declarative.test.tsx +137 -0
- package/src/elements/conversation-list.stories.tsx +243 -0
- package/src/elements/conversation-list.tsx +80 -0
- package/src/elements/css.ts +5 -0
- package/src/elements/default-input.tsx +247 -0
- package/src/elements/define.tsx +171 -0
- package/src/elements/element-meta.json +3314 -0
- package/src/elements/element-types.d.ts +710 -0
- package/src/elements/embed.stories.tsx +213 -0
- package/src/elements/embed.tsx +35 -0
- package/src/elements/empty.stories.tsx +111 -0
- package/src/elements/empty.tsx +29 -0
- package/src/elements/feedback-bar.stories.tsx +114 -0
- package/src/elements/feedback-bar.tsx +61 -0
- package/src/elements/file-tree.stories.tsx +134 -0
- package/src/elements/file-tree.tsx +52 -0
- package/src/elements/file-upload.stories.tsx +82 -0
- package/src/elements/file-upload.tsx +44 -0
- package/src/elements/form.stories.tsx +248 -0
- package/src/elements/form.tsx +43 -0
- package/src/elements/framework-usage.json +563 -0
- package/src/elements/image.stories.tsx +71 -0
- package/src/elements/image.tsx +32 -0
- package/src/elements/link-preview.stories.tsx +209 -0
- package/src/elements/link-preview.tsx +34 -0
- package/src/elements/loader.stories.tsx +88 -0
- package/src/elements/loader.tsx +25 -0
- package/src/elements/markdown.stories.tsx +76 -0
- package/src/elements/markdown.tsx +38 -0
- package/src/elements/message-skills.declarative.test.tsx +104 -0
- package/src/elements/message-skills.stories.tsx +114 -0
- package/src/elements/message-skills.tsx +85 -0
- package/src/elements/message.stories.tsx +218 -0
- package/src/elements/message.tsx +162 -0
- package/src/elements/model-switcher.declarative.test.tsx +130 -0
- package/src/elements/model-switcher.stories.tsx +198 -0
- package/src/elements/model-switcher.tsx +93 -0
- package/src/elements/popover.stories.tsx +80 -0
- package/src/elements/popover.tsx +59 -0
- package/src/elements/prompt-input-slash-command.test.tsx +128 -0
- package/src/elements/prompt-input-stoppable.test.tsx +88 -0
- package/src/elements/prompt-input-toolbar-actions.test.tsx +120 -0
- package/src/elements/prompt-input.stories.tsx +331 -0
- package/src/elements/prompt-input.tsx +185 -0
- package/src/elements/prompt-suggestions.declarative.test.tsx +164 -0
- package/src/elements/prompt-suggestions.stories.tsx +213 -0
- package/src/elements/prompt-suggestions.tsx +94 -0
- package/src/elements/reasoning.stories.tsx +77 -0
- package/src/elements/reasoning.tsx +50 -0
- package/src/elements/register.ts +56 -0
- package/src/elements/remote.stories.tsx +314 -0
- package/src/elements/remote.tsx +221 -0
- package/src/elements/resizable.d.ts +27 -0
- package/src/elements/resizable.stories.tsx +426 -0
- package/src/elements/resizable.tsx +553 -0
- package/src/elements/response-stream.stories.tsx +79 -0
- package/src/elements/response-stream.tsx +40 -0
- package/src/elements/scroll-button.stories.tsx +202 -0
- package/src/elements/scroll-button.test.tsx +148 -0
- package/src/elements/scroll-button.tsx +126 -0
- package/src/elements/source-list.stories.tsx +143 -0
- package/src/elements/source.stories.tsx +88 -0
- package/src/elements/source.tsx +120 -0
- package/src/elements/styles.css +199 -0
- package/src/elements/switch.stories.tsx +56 -0
- package/src/elements/switch.tsx +43 -0
- package/src/elements/tasks.stories.tsx +237 -0
- package/src/elements/tasks.tsx +46 -0
- package/src/elements/text-shimmer.stories.tsx +64 -0
- package/src/elements/text-shimmer.tsx +28 -0
- package/src/elements/thinking-bar.stories.tsx +72 -0
- package/src/elements/thinking-bar.tsx +34 -0
- package/src/elements/tool.stories.tsx +89 -0
- package/src/elements/tool.tsx +23 -0
- package/src/elements/voice-input.stories.tsx +88 -0
- package/src/elements/voice-input.tsx +41 -0
- package/src/index.ts +253 -0
- package/src/primitives/card-contract.ts +71 -0
- package/src/primitives/card-host.tsx +35 -0
- package/src/primitives/card-registry.tsx +67 -0
- package/src/primitives/card-resolution.ts +36 -0
- package/src/primitives/card-routing.ts +79 -0
- package/src/primitives/card-schemas/card-envelope.schema.json +14 -0
- package/src/primitives/card-schemas/card-event.schema.json +12 -0
- package/src/primitives/card-schemas/choice.schema.json +70 -0
- package/src/primitives/card-schemas/confirm.schema.json +65 -0
- package/src/primitives/card-schemas/embed.schema.json +65 -0
- package/src/primitives/card-schemas/form.result.schema.json +7 -0
- package/src/primitives/card-schemas/form.schema.json +33 -0
- package/src/primitives/card-schemas/link.schema.json +56 -0
- package/src/primitives/card-schemas/tasks.result.schema.json +16 -0
- package/src/primitives/card-schemas/tasks.schema.json +78 -0
- package/src/primitives/card-validate.ts +95 -0
- package/src/primitives/chat-config.tsx +76 -0
- package/src/primitives/controllable.test.ts +47 -0
- package/src/primitives/controllable.ts +21 -0
- package/src/primitives/embed-providers.ts +254 -0
- package/src/primitives/highlighter.ts +157 -0
- package/src/primitives/link-preview.ts +87 -0
- package/src/primitives/pdf-preview.ts +121 -0
- package/src/primitives/use-auto-resize.ts +31 -0
- package/src/primitives/use-resize-observer.ts +12 -0
- package/src/primitives/use-stick-to-bottom.ts +43 -0
- package/src/primitives/use-text-stream.ts +112 -0
- package/src/primitives/use-voice-recorder.ts +50 -0
- package/src/remote/host-embed.ts +345 -0
- package/src/remote/index.ts +2 -0
- package/src/remote/origin.ts +30 -0
- package/src/remote/provider-runtime.ts +259 -0
- package/src/remote/provider.ts +2 -0
- package/src/remote/validate.ts +22 -0
- package/src/remote/version.ts +12 -0
- package/src/remote/wire.ts +48 -0
- package/src/stories/chat-panel-layout.stories.tsx +145 -0
- package/src/stories/chat-scene.tsx +571 -0
- package/src/stories/checkpoint-restore.stories.tsx +256 -0
- package/src/stories/context-usage.stories.tsx +212 -0
- package/src/stories/conversation-with-reasoning.stories.tsx +182 -0
- package/src/stories/conversation-with-sources.stories.tsx +471 -0
- package/src/stories/docs/Accessibility.mdx +119 -0
- package/src/stories/docs/ChildElements.mdx +269 -0
- package/src/stories/docs/ForAIAgents.mdx +162 -0
- package/src/stories/docs/GettingStarted.mdx +65 -0
- package/src/stories/docs/Installation.mdx +83 -0
- package/src/stories/docs/Introduction.mdx +50 -0
- package/src/stories/docs/SolidJsAdvanced.mdx +17 -0
- package/src/stories/docs/Theming.mdx +85 -0
- package/src/stories/docs/element-controls.ts +121 -0
- package/src/stories/docs/frameworks/Angular.mdx +245 -0
- package/src/stories/docs/frameworks/Html.mdx +227 -0
- package/src/stories/docs/frameworks/Overview.mdx +47 -0
- package/src/stories/docs/frameworks/React.mdx +227 -0
- package/src/stories/docs/frameworks/Solid.mdx +173 -0
- package/src/stories/docs/frameworks/Svelte.mdx +194 -0
- package/src/stories/docs/frameworks/Vue.mdx +238 -0
- package/src/stories/docs/generative-ui-overview.mdx +186 -0
- package/src/stories/docs/recipes/SpeechToText.mdx +7 -0
- package/src/stories/docs/recipes/Streaming.mdx +68 -0
- package/src/stories/docs/recipes/TextToSpeech.mdx +35 -0
- package/src/stories/docs/theme-editor/canvas.tsx +32 -0
- package/src/stories/docs/theme-editor/inspector.tsx +66 -0
- package/src/stories/docs/theme-editor/presets.test.ts +32 -0
- package/src/stories/docs/theme-editor/presets.ts +64 -0
- package/src/stories/docs/theme-editor/theme-css.test.ts +19 -0
- package/src/stories/docs/theme-editor/theme-css.ts +15 -0
- package/src/stories/docs/theme-editor/theme-editor.tsx +146 -0
- package/src/stories/docs/theme-tokens.tsx +174 -0
- package/src/stories/examples/ChoosingComponents.mdx +106 -0
- package/src/stories/examples/sample-data.ts +79 -0
- package/src/stories/examples/usage/checkpoint-restore.ts +156 -0
- package/src/stories/examples/usage/context-usage.ts +591 -0
- package/src/stories/examples/usage/conversation-with-reasoning.ts +224 -0
- package/src/stories/examples/usage/conversation-with-sources.ts +589 -0
- package/src/stories/examples/usage/empty-state.ts +144 -0
- package/src/stories/examples/usage/full-chat-app.ts +277 -0
- package/src/stories/examples/usage/index.ts +63 -0
- package/src/stories/examples/usage/message-actions.ts +704 -0
- package/src/stories/examples/usage/pattern-centered-conversation.ts +446 -0
- package/src/stories/examples/usage/pattern-chat-panel-layout.ts +442 -0
- package/src/stories/examples/usage/pattern-docked-widget.ts +479 -0
- package/src/stories/examples/usage/prompt-input-variants.ts +1356 -0
- package/src/stories/examples/usage/streaming-response.ts +687 -0
- package/src/stories/examples/usage/types.ts +33 -0
- package/src/stories/full-chat.stories.tsx +18 -0
- package/src/stories/message-actions.stories.tsx +230 -0
- package/src/stories/pattern-centered-conversation.stories.tsx +93 -0
- package/src/stories/pattern-docked-widget.stories.tsx +93 -0
- package/src/stories/pattern-empty-state.stories.tsx +76 -0
- package/src/stories/prompt-input-variants.stories.tsx +456 -0
- package/src/stories/streaming-response.stories.tsx +438 -0
- package/src/stories/theme-editor.stories.tsx +16 -0
- package/src/stories/token-reference.stories.tsx +18 -0
- package/src/stories/typography.stories.tsx +78 -0
- package/src/types.ts +47 -0
- package/src/ui/action-icons.ts +52 -0
- package/src/ui/avatar.stories.tsx +103 -0
- package/src/ui/avatar.tsx +23 -0
- package/src/ui/badge.stories.tsx +86 -0
- package/src/ui/badge.tsx +21 -0
- package/src/ui/button.stories.tsx +145 -0
- package/src/ui/button.tsx +38 -0
- package/src/ui/collapsible.stories.tsx +69 -0
- package/src/ui/collapsible.tsx +125 -0
- package/src/ui/dropdown.stories.tsx +59 -0
- package/src/ui/dropdown.tsx +196 -0
- package/src/ui/hover-card.stories.tsx +77 -0
- package/src/ui/hover-card.test.tsx +30 -0
- package/src/ui/hover-card.tsx +172 -0
- package/src/ui/overlay.stories.tsx +115 -0
- package/src/ui/overlay.tsx +158 -0
- package/src/ui/popover.stories.tsx +81 -0
- package/src/ui/popover.test.tsx +99 -0
- package/src/ui/popover.tsx +92 -0
- package/src/ui/resizable.stories.tsx +236 -0
- package/src/ui/resizable.tsx +576 -0
- package/src/ui/scroll-area.stories.tsx +50 -0
- package/src/ui/scroll-area.tsx +15 -0
- package/src/ui/separator.stories.tsx +81 -0
- package/src/ui/separator.tsx +10 -0
- package/src/ui/skeleton.stories.tsx +337 -0
- package/src/ui/skeleton.tsx +16 -0
- package/src/ui/switch.stories.tsx +51 -0
- package/src/ui/switch.test.tsx +59 -0
- package/src/ui/switch.tsx +62 -0
- package/src/ui/textarea.stories.tsx +76 -0
- package/src/ui/textarea.tsx +21 -0
- package/src/ui/tooltip.stories.tsx +74 -0
- package/src/ui/tooltip.tsx +68 -0
- package/src/utils/cn.ts +24 -0
- package/theme.css +187 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// src/elements/cards.tsx
|
|
2
|
+
// <kai-cards> — the web-component list dispatcher. Renders one child kai-* element per
|
|
3
|
+
// envelope (by type→tag), propagates its theme, and routes children's bubbling
|
|
4
|
+
// `kai-card` events through an optional `policy`. The raw events keep bubbling past
|
|
5
|
+
// <kai-cards> (composed) so document-level listeners still work. Unknown types render
|
|
6
|
+
// the Solid CardFallback inline and emit a contract `error`.
|
|
7
|
+
import { For, Show, createEffect, onCleanup, onMount, type JSX } from 'solid-js';
|
|
8
|
+
import { Dynamic } from 'solid-js/web';
|
|
9
|
+
import { defineWebComponent } from './define';
|
|
10
|
+
import type { CardEnvelope, CardEvent, CardPolicy } from '../primitives/card-contract';
|
|
11
|
+
import { CARD_EVENT_NAME, emitCardEvent, routeCardEvent } from '../primitives/card-routing';
|
|
12
|
+
import { mergeCardTags } from '../primitives/card-registry';
|
|
13
|
+
import { CardFallback } from '../components/card-fallback';
|
|
14
|
+
// Register the built-in child card elements so that importing <kai-cards> is self-contained.
|
|
15
|
+
import './form';
|
|
16
|
+
import './confirm-card';
|
|
17
|
+
import './tasks';
|
|
18
|
+
import './choice';
|
|
19
|
+
import './link-preview';
|
|
20
|
+
import './embed';
|
|
21
|
+
|
|
22
|
+
interface Props extends Record<string, unknown> {
|
|
23
|
+
/** The stream of card envelopes to render. Set as a JS PROPERTY: `el.cards = [...]`. */
|
|
24
|
+
cards?: CardEnvelope[];
|
|
25
|
+
/** Optional type→tag overrides/additions (merged over the built-ins). Property: `el.types`.
|
|
26
|
+
* Typed as a plain string map (not the `CardTagMap` alias) so the generated React
|
|
27
|
+
* wrapper inlines it instead of emitting an unresolved named type. */
|
|
28
|
+
types?: Record<string, string>;
|
|
29
|
+
/** Optional CardPolicy handling child events. Property: `el.policy`. */
|
|
30
|
+
policy?: CardPolicy;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** A single resolved child: a known kai-* tag (props set imperatively) or the fallback. */
|
|
34
|
+
function CardSlot(props: { envelope: CardEnvelope; tag?: string; theme: string; emit: (e: CardEvent) => void }): JSX.Element {
|
|
35
|
+
let ref: HTMLElement | undefined;
|
|
36
|
+
// Set object/string props as DOM properties on the custom element (reactive).
|
|
37
|
+
createEffect(() => {
|
|
38
|
+
if (!ref) return;
|
|
39
|
+
(ref as unknown as { data: unknown }).data = props.envelope.data;
|
|
40
|
+
(ref as unknown as { cardId: string }).cardId = props.envelope.id;
|
|
41
|
+
if (props.envelope.title != null) (ref as unknown as { heading: string }).heading = props.envelope.title;
|
|
42
|
+
(ref as unknown as { resolution: unknown }).resolution = props.envelope.resolution;
|
|
43
|
+
ref.setAttribute('theme', props.theme);
|
|
44
|
+
});
|
|
45
|
+
// Hoist the unknown-type error emit to onMount to avoid side-effect-in-JSX lint issue
|
|
46
|
+
// and to ensure exactly one error fires.
|
|
47
|
+
onMount(() => {
|
|
48
|
+
if (!props.tag) {
|
|
49
|
+
props.emit({ kind: 'error', cardId: props.envelope.id, message: `Unsupported card type: ${props.envelope.type}` });
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return (
|
|
53
|
+
<Show
|
|
54
|
+
when={props.tag}
|
|
55
|
+
fallback={<CardFallback type={props.envelope.type} cardId={props.envelope.id} />}
|
|
56
|
+
>
|
|
57
|
+
{(tag) => <Dynamic component={tag()} ref={ref} />}
|
|
58
|
+
</Show>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
defineWebComponent<Props>(
|
|
63
|
+
'kai-cards',
|
|
64
|
+
{ cards: undefined, types: undefined, policy: undefined },
|
|
65
|
+
(props, { element }) => {
|
|
66
|
+
// Route children's bubbling kai-card events through the policy. Attached to the host
|
|
67
|
+
// element so composed events from each child's shadow root are caught as they bubble.
|
|
68
|
+
// The handler reads `props.policy` at EVENT time (not mount time) so setting
|
|
69
|
+
// `el.policy` after the element is in the DOM — the standard host pattern — works.
|
|
70
|
+
onMount(() => {
|
|
71
|
+
const handler = (e: Event) =>
|
|
72
|
+
routeCardEvent(props.policy ?? {}, (e as CustomEvent<CardEvent>).detail);
|
|
73
|
+
element.addEventListener(CARD_EVENT_NAME, handler as EventListener);
|
|
74
|
+
onCleanup(() => element.removeEventListener(CARD_EVENT_NAME, handler as EventListener));
|
|
75
|
+
});
|
|
76
|
+
// Read the facade's REACTIVE `theme` prop, not element.getAttribute (which is
|
|
77
|
+
// not a tracked dependency) — otherwise a theme change on <kai-cards> after the
|
|
78
|
+
// children first render never propagates, leaving each child card stuck on its
|
|
79
|
+
// initial 'auto' (which follows the OS, so cards looked "always dark").
|
|
80
|
+
const theme = () => ((props as { theme?: string }).theme ?? 'auto');
|
|
81
|
+
const tags = () => mergeCardTags(props.types);
|
|
82
|
+
return (
|
|
83
|
+
<div class="flex flex-col gap-3">
|
|
84
|
+
<For each={props.cards ?? []}>
|
|
85
|
+
{(env) => (
|
|
86
|
+
<CardSlot
|
|
87
|
+
envelope={env}
|
|
88
|
+
tag={tags()[env.type]}
|
|
89
|
+
theme={theme()}
|
|
90
|
+
emit={(e) => emitCardEvent(element, e)}
|
|
91
|
+
/>
|
|
92
|
+
)}
|
|
93
|
+
</For>
|
|
94
|
+
</div>
|
|
95
|
+
);
|
|
96
|
+
},
|
|
97
|
+
);
|
|
@@ -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 kai-* 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 kai-* 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 kai-* 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 `kai-*` 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("kai-submit", …)`). Register everything once with `import "@kitn.ai/ui/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
|
+
<kai-conversations style="display:block;height:320px"></kai-conversations>
|
|
125
|
+
<kai-prompt-input placeholder="Ask anything… (try typing /)"></kai-prompt-input>
|
|
126
|
+
|
|
127
|
+
<script type="module">
|
|
128
|
+
import '@kitn.ai/ui/elements';
|
|
129
|
+
|
|
130
|
+
const list = document.querySelector('kai-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('kai-conversation-select', (e) => (list.activeId = e.detail.id));
|
|
137
|
+
|
|
138
|
+
const input = document.querySelector('kai-prompt-input');
|
|
139
|
+
input.slashCommands = [
|
|
140
|
+
{ id: 'summarize', label: '/summarize', description: 'Summarize', category: 'Actions' },
|
|
141
|
+
];
|
|
142
|
+
input.addEventListener('kai-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('kai-conversation-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="kai-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
|
+
<kai-conversations ref={(e) => (list = e)} style={{ display: 'block', height: '100%' }} />
|
|
161
|
+
</div>
|
|
162
|
+
</Spec>
|
|
163
|
+
<Spec tag="kai-prompt-input" note='slash commands — type "/"'>
|
|
164
|
+
<kai-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
|
+
<kai-message id="assistant"></kai-message>
|
|
176
|
+
<kai-message id="user"></kai-message>
|
|
177
|
+
<kai-markdown id="md"></kai-markdown>
|
|
178
|
+
<kai-reasoning id="reason" label="Reasoning" streaming></kai-reasoning>
|
|
179
|
+
<kai-chain-of-thought id="cot"></kai-chain-of-thought>
|
|
180
|
+
<kai-code-block id="code" language="ts"></kai-code-block>
|
|
181
|
+
<kai-tool id="tool" open></kai-tool>
|
|
182
|
+
|
|
183
|
+
<script type="module">
|
|
184
|
+
import '@kitn.ai/ui/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="kai-message" note='role="assistant" — reasoning + tool + attachment + actions'>
|
|
224
|
+
<kai-message ref={(e) => (msgA = e)} />
|
|
225
|
+
</Spec>
|
|
226
|
+
<Spec tag="kai-message" note='role="user"'>
|
|
227
|
+
<kai-message ref={(e) => (msgU = e)} />
|
|
228
|
+
</Spec>
|
|
229
|
+
<Spec tag="kai-markdown" note="token-themed markdown + fenced code">
|
|
230
|
+
<kai-markdown ref={(e) => (md = e)} />
|
|
231
|
+
</Spec>
|
|
232
|
+
<Spec tag="kai-reasoning" note="collapsible thinking; auto-opens while streaming">
|
|
233
|
+
<kai-reasoning ref={(e) => (reason = e)} />
|
|
234
|
+
</Spec>
|
|
235
|
+
<Spec tag="kai-chain-of-thought" note="step-by-step reasoning with connectors">
|
|
236
|
+
<kai-chain-of-thought ref={(e) => (cot = e)} />
|
|
237
|
+
</Spec>
|
|
238
|
+
<Spec tag="kai-code-block" note='language="ts" — highlighted, copyable'>
|
|
239
|
+
<kai-code-block ref={(e) => (code = e)} />
|
|
240
|
+
</Spec>
|
|
241
|
+
<Spec tag="kai-tool" note="open — input, output, state badge">
|
|
242
|
+
<kai-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
|
+
<kai-attachments id="inline" variant="inline" hover-card></kai-attachments>
|
|
254
|
+
<kai-attachments id="grid" variant="grid" removable></kai-attachments>
|
|
255
|
+
<kai-image id="img" alt="demo" style="width:96px"></kai-image>
|
|
256
|
+
<kai-source href="https://kitn.dev" headline="kitn — the kit"
|
|
257
|
+
description="Composable chat UI." show-favicon></kai-source>
|
|
258
|
+
<kai-sources id="srcs"></kai-sources>
|
|
259
|
+
|
|
260
|
+
<script type="module">
|
|
261
|
+
import '@kitn.ai/ui/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('kai-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('kai-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="kai-attachments" note='variant="inline" hover-card'>
|
|
300
|
+
<kai-attachments ref={(e) => (inline = e)} />
|
|
301
|
+
</Spec>
|
|
302
|
+
<Spec tag="kai-attachments" note='variant="grid" removable'>
|
|
303
|
+
<kai-attachments ref={(e) => (grid = e)} />
|
|
304
|
+
</Spec>
|
|
305
|
+
<Spec tag="kai-image" note="base64 / byte-array image with skeleton">
|
|
306
|
+
<kai-image ref={(e) => (img = e)} style={{ width: '96px' }} />
|
|
307
|
+
</Spec>
|
|
308
|
+
<Spec tag="kai-source" note="show-favicon — citation with hover preview">
|
|
309
|
+
<kai-source ref={(e) => (src = e)} />
|
|
310
|
+
</Spec>
|
|
311
|
+
<Spec tag="kai-sources" note="wrapped row of citations">
|
|
312
|
+
<kai-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
|
+
<kai-suggestions id="suggs"></kai-suggestions>
|
|
324
|
+
<kai-file-upload></kai-file-upload>
|
|
325
|
+
<kai-voice-input id="voice"></kai-voice-input>
|
|
326
|
+
<kai-thinking-bar text="Thinking…" stoppable></kai-thinking-bar>
|
|
327
|
+
|
|
328
|
+
<script type="module">
|
|
329
|
+
import '@kitn.ai/ui/elements';
|
|
330
|
+
const suggs = document.getElementById('suggs');
|
|
331
|
+
suggs.suggestions = ['Explain the architecture', 'Show me a code example'];
|
|
332
|
+
suggs.addEventListener('kai-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('kai-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="kai-suggestions" note="suggestion chips; click fires select">
|
|
351
|
+
<kai-suggestions ref={(e) => (suggs = e)} />
|
|
352
|
+
</Spec>
|
|
353
|
+
<Spec tag="kai-file-upload" note="click / drag-drop dropzone">
|
|
354
|
+
<kai-file-upload />
|
|
355
|
+
</Spec>
|
|
356
|
+
<Spec tag="kai-voice-input · kai-thinking-bar" note="mic capture + shimmering thinking bar">
|
|
357
|
+
<div style={{ display: 'flex', gap: '8px', 'align-items': 'center' }}>
|
|
358
|
+
<kai-voice-input ref={(e) => (voice = e)} />
|
|
359
|
+
<kai-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
|
+
<kai-model-switcher id="models"></kai-model-switcher>
|
|
372
|
+
<kai-context id="ctx"></kai-context>
|
|
373
|
+
<kai-scope-picker id="scope"></kai-scope-picker>
|
|
374
|
+
<kai-checkpoint label="Checkpoint" tooltip="Restore"></kai-checkpoint>
|
|
375
|
+
<kai-skills id="skills"></kai-skills>
|
|
376
|
+
<kai-feedback-bar bar-title="Was this helpful?"></kai-feedback-bar>
|
|
377
|
+
|
|
378
|
+
<script type="module">
|
|
379
|
+
import '@kitn.ai/ui/elements';
|
|
380
|
+
const ms = document.getElementById('models');
|
|
381
|
+
ms.models = [{ id: 'opus', name: 'Claude Opus', provider: 'Anthropic' }];
|
|
382
|
+
ms.currentModel = 'opus';
|
|
383
|
+
ms.addEventListener('kai-model-change', (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('kai-model-change', (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="kai-model-switcher" note="model dropdown; emits modelchange">
|
|
408
|
+
<kai-model-switcher ref={(e) => (ms = e)} />
|
|
409
|
+
</Spec>
|
|
410
|
+
<Spec tag="kai-context" note="token-usage meter with breakdown">
|
|
411
|
+
<kai-context ref={(e) => (ctx = e)} />
|
|
412
|
+
</Spec>
|
|
413
|
+
<Spec tag="kai-scope-picker" note="scope a chat by author or tag">
|
|
414
|
+
<kai-scope-picker ref={(e) => (scope = e)} />
|
|
415
|
+
</Spec>
|
|
416
|
+
<Spec tag="kai-checkpoint · kai-skills" note="bookmark button + active-skill badges">
|
|
417
|
+
<div style={{ display: 'flex', gap: '8px', 'align-items': 'center' }}>
|
|
418
|
+
<kai-checkpoint ref={(e) => (cp = e)} />
|
|
419
|
+
<kai-skills ref={(e) => (skills = e)} />
|
|
420
|
+
</div>
|
|
421
|
+
</Spec>
|
|
422
|
+
<Spec tag="kai-feedback-bar" note="inline thumbs up/down banner">
|
|
423
|
+
<kai-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
|
+
<kai-loader variant="circular"></kai-loader>
|
|
435
|
+
<kai-loader variant="dots"></kai-loader>
|
|
436
|
+
<kai-text-shimmer text="Generating response…"></kai-text-shimmer>
|
|
437
|
+
<kai-response-stream id="stream" speed="30"></kai-response-stream>
|
|
438
|
+
<kai-empty empty-title="No conversations yet" description="Start chatting to see them here.">
|
|
439
|
+
<span slot="media">✦</span>
|
|
440
|
+
</kai-empty>
|
|
441
|
+
|
|
442
|
+
<script type="module">
|
|
443
|
+
import '@kitn.ai/ui/elements';
|
|
444
|
+
const stream = document.getElementById('stream');
|
|
445
|
+
stream.text = 'This text reveals with a typewriter animation, character by character.';
|
|
446
|
+
stream.addEventListener('kai-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="kai-loader" note="twelve loader styles">
|
|
468
|
+
<div style={{ display: 'flex', gap: '24px', 'align-items': 'center', 'flex-wrap': 'wrap' }}>
|
|
469
|
+
<kai-loader ref={(e) => (l1 = e)} />
|
|
470
|
+
<kai-loader ref={(e) => (l2 = e)} />
|
|
471
|
+
<kai-loader ref={(e) => (l3 = e)} />
|
|
472
|
+
<kai-loader ref={(e) => (l4 = e)} />
|
|
473
|
+
<kai-loader ref={(e) => (l5 = e)} />
|
|
474
|
+
</div>
|
|
475
|
+
</Spec>
|
|
476
|
+
<Spec tag="kai-text-shimmer" note="animated shimmering text">
|
|
477
|
+
<kai-text-shimmer ref={(e) => (shimmer = e)} />
|
|
478
|
+
</Spec>
|
|
479
|
+
<Spec tag="kai-response-stream" note='mode="typewriter" — emits complete'>
|
|
480
|
+
<kai-response-stream ref={(e) => (stream = e)} />
|
|
481
|
+
</Spec>
|
|
482
|
+
<Spec tag="kai-empty" note="empty-state layout — media & default slots">
|
|
483
|
+
<kai-empty ref={(e) => (empty = e)}>
|
|
484
|
+
<span slot="media">✦</span>
|
|
485
|
+
</kai-empty>
|
|
486
|
+
</Spec>
|
|
487
|
+
</Grid>
|
|
488
|
+
);
|
|
489
|
+
},
|
|
490
|
+
parameters: { docs: { source: { code: STATUS_SNIPPET, language: 'html' } } },
|
|
491
|
+
};
|