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