@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,87 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { fn } from 'storybook/test';
|
|
3
|
+
import { ThinkingBar } from './thinking-bar';
|
|
4
|
+
import { componentDescription } from '../stories/docs/element-controls';
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'Solid (Advanced)/Elements/ThinkingBar',
|
|
8
|
+
component: ThinkingBar,
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
parameters: {
|
|
11
|
+
layout: 'padded',
|
|
12
|
+
docs: {
|
|
13
|
+
controls: { exclude: ['use:eventListener'] },
|
|
14
|
+
description: componentDescription([
|
|
15
|
+
'A status row that shows a shimmering "thinking" label, optionally clickable to expand reasoning, with an optional stop/cancel action.',
|
|
16
|
+
'**When to use:** while the assistant is generating or reasoning, to show live activity and give the user a way to interrupt or to open the reasoning trace.',
|
|
17
|
+
'**How to use:** set `text` for the label. Pass `onClick` to make the label a button (adds a chevron) — typically to toggle a reasoning panel. Pass `onStop` (with optional `stopLabel`) to render the interrupt action.',
|
|
18
|
+
'**Placement:** above or in place of a streaming message, or at the top of a reasoning/chain-of-thought block.',
|
|
19
|
+
]),
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
argTypes: {
|
|
23
|
+
text: {
|
|
24
|
+
control: 'text',
|
|
25
|
+
description: 'Label shown with the shimmer effect.',
|
|
26
|
+
table: { defaultValue: { summary: 'Thinking' } },
|
|
27
|
+
},
|
|
28
|
+
stopLabel: {
|
|
29
|
+
control: 'text',
|
|
30
|
+
description: 'Label for the stop/cancel action (only shown when `onStop` is set).',
|
|
31
|
+
table: { defaultValue: { summary: 'Answer now' } },
|
|
32
|
+
},
|
|
33
|
+
class: {
|
|
34
|
+
control: 'text',
|
|
35
|
+
description: 'Additional CSS classes for the container.',
|
|
36
|
+
},
|
|
37
|
+
onClick: {
|
|
38
|
+
action: 'click',
|
|
39
|
+
description: 'When set, the label becomes a button (with chevron) and this fires on click.',
|
|
40
|
+
table: { category: 'Events' },
|
|
41
|
+
},
|
|
42
|
+
onStop: {
|
|
43
|
+
action: 'stop',
|
|
44
|
+
description: 'When set, renders the stop action and fires when it is clicked.',
|
|
45
|
+
table: { category: 'Events' },
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
args: {
|
|
49
|
+
text: 'Thinking',
|
|
50
|
+
stopLabel: 'Answer now',
|
|
51
|
+
onStop: fn(),
|
|
52
|
+
},
|
|
53
|
+
render: (args) => <ThinkingBar {...args} />,
|
|
54
|
+
} satisfies Meta<typeof ThinkingBar>;
|
|
55
|
+
|
|
56
|
+
export default meta;
|
|
57
|
+
type Story = StoryObj<typeof meta>;
|
|
58
|
+
|
|
59
|
+
const IMPORT = `import { ThinkingBar } from '@kitn.ai/ui';`;
|
|
60
|
+
const src = (code: string) => ({
|
|
61
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
/** Interactive playground — tweak the controls to explore the thinking bar. */
|
|
65
|
+
export const Playground: Story = {
|
|
66
|
+
...src(`<ThinkingBar text="Thinking" onStop={() => stop()} />`),
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const Default: Story = {
|
|
70
|
+
args: { onStop: undefined } as never,
|
|
71
|
+
...src(`<ThinkingBar />`),
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const WithStopButton: Story = {
|
|
75
|
+
args: { onStop: fn() },
|
|
76
|
+
...src(`<ThinkingBar onStop={() => stopGeneration()} />`),
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const CustomText: Story = {
|
|
80
|
+
args: { text: 'Analyzing documents', stopLabel: 'Cancel', onStop: fn() },
|
|
81
|
+
...src(`<ThinkingBar text="Analyzing documents" stopLabel="Cancel" onStop={() => cancel()} />`),
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const Clickable: Story = {
|
|
85
|
+
args: { text: 'Reasoning', onClick: fn(), onStop: fn() },
|
|
86
|
+
...src(`<ThinkingBar\n text="Reasoning"\n onClick={() => toggleReasoning()}\n onStop={() => stop()}\n/>`),
|
|
87
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type JSX, splitProps, Show } from 'solid-js';
|
|
2
|
+
import { cn } from '../utils/cn';
|
|
3
|
+
import { TextShimmer } from './text-shimmer';
|
|
4
|
+
import { ChevronRight } from 'lucide-solid';
|
|
5
|
+
|
|
6
|
+
export interface ThinkingBarProps {
|
|
7
|
+
class?: string;
|
|
8
|
+
text?: string;
|
|
9
|
+
onStop?: () => void;
|
|
10
|
+
stopLabel?: string;
|
|
11
|
+
onClick?: () => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function ThinkingBar(props: ThinkingBarProps) {
|
|
15
|
+
const [local] = splitProps(props, ['class', 'text', 'onStop', 'stopLabel', 'onClick']);
|
|
16
|
+
|
|
17
|
+
const text = () => local.text ?? 'Thinking';
|
|
18
|
+
const stopLabel = () => local.stopLabel ?? 'Answer now';
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div class={cn('flex w-full items-center justify-between', local.class)}>
|
|
22
|
+
<Show
|
|
23
|
+
when={local.onClick}
|
|
24
|
+
fallback={
|
|
25
|
+
<TextShimmer class="cursor-default text-sm font-medium">{text()}</TextShimmer>
|
|
26
|
+
}
|
|
27
|
+
>
|
|
28
|
+
<button
|
|
29
|
+
type="button"
|
|
30
|
+
onClick={local.onClick}
|
|
31
|
+
class="flex items-center gap-1 text-sm transition-opacity hover:opacity-80"
|
|
32
|
+
>
|
|
33
|
+
<TextShimmer class="text-sm font-medium">{text()}</TextShimmer>
|
|
34
|
+
<ChevronRight class="text-muted-foreground size-4" />
|
|
35
|
+
</button>
|
|
36
|
+
</Show>
|
|
37
|
+
<Show when={local.onStop}>
|
|
38
|
+
<button
|
|
39
|
+
onClick={local.onStop}
|
|
40
|
+
type="button"
|
|
41
|
+
class="text-muted-foreground hover:text-foreground border-muted-foreground/50 hover:border-foreground border-b border-dotted text-sm transition-colors"
|
|
42
|
+
>
|
|
43
|
+
{stopLabel()}
|
|
44
|
+
</button>
|
|
45
|
+
</Show>
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { ThinkingBar };
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { Tool } from './tool';
|
|
3
|
+
import type { ToolPart } from './tool';
|
|
4
|
+
import { componentDescription } from '../stories/docs/element-controls';
|
|
5
|
+
|
|
6
|
+
const streamingPart: ToolPart = {
|
|
7
|
+
type: 'search_documents',
|
|
8
|
+
state: 'input-streaming',
|
|
9
|
+
input: { query: 'SolidJS reactive primitives' },
|
|
10
|
+
toolCallId: 'call_abc123',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const readyPart: ToolPart = {
|
|
14
|
+
type: 'search_documents',
|
|
15
|
+
state: 'input-available',
|
|
16
|
+
input: { query: 'SolidJS reactive primitives', limit: 10 },
|
|
17
|
+
toolCallId: 'call_abc123',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const completedPart: ToolPart = {
|
|
21
|
+
type: 'search_documents',
|
|
22
|
+
state: 'output-available',
|
|
23
|
+
input: { query: 'SolidJS reactive primitives', limit: 10 },
|
|
24
|
+
output: { results: [{ title: 'Signals', score: 0.95 }, { title: 'Effects', score: 0.87 }] },
|
|
25
|
+
toolCallId: 'call_abc123',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const errorPart: ToolPart = {
|
|
29
|
+
type: 'search_documents',
|
|
30
|
+
state: 'output-error',
|
|
31
|
+
input: { query: 'SolidJS reactive primitives' },
|
|
32
|
+
errorText: 'Connection timeout: unable to reach the search service after 30 seconds.',
|
|
33
|
+
toolCallId: 'call_abc123',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const meta = {
|
|
37
|
+
title: 'Solid (Advanced)/Elements/Tool',
|
|
38
|
+
component: Tool,
|
|
39
|
+
tags: ['autodocs'],
|
|
40
|
+
parameters: {
|
|
41
|
+
layout: 'padded',
|
|
42
|
+
docs: {
|
|
43
|
+
controls: { exclude: ['use:eventListener'] },
|
|
44
|
+
description: componentDescription([
|
|
45
|
+
'A collapsible panel that visualizes a single tool call — its name, state (processing / ready / completed / error), input, output, error, and call ID.',
|
|
46
|
+
'**When to use:** to surface assistant tool/function calls in the conversation, so users can inspect what was run and what came back.',
|
|
47
|
+
'**How to use:** pass a `toolPart` describing the call (`type`, `state`, optional `input`, `output`, `errorText`, `toolCallId`). State drives the icon and badge automatically. Set `defaultOpen` to start expanded.',
|
|
48
|
+
'**Placement:** inline within an assistant message, typically between text segments where the tool was invoked.',
|
|
49
|
+
]),
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
argTypes: {
|
|
53
|
+
toolPart: {
|
|
54
|
+
control: 'object',
|
|
55
|
+
description: 'The tool call to render — `type`, `state`, and optional `input`/`output`/`errorText`/`toolCallId`.',
|
|
56
|
+
},
|
|
57
|
+
defaultOpen: {
|
|
58
|
+
control: 'boolean',
|
|
59
|
+
description: 'Whether the panel starts expanded.',
|
|
60
|
+
table: { defaultValue: { summary: 'false' } },
|
|
61
|
+
},
|
|
62
|
+
class: {
|
|
63
|
+
control: 'text',
|
|
64
|
+
description: 'Additional CSS classes for the container.',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
args: {
|
|
68
|
+
toolPart: completedPart,
|
|
69
|
+
defaultOpen: true,
|
|
70
|
+
},
|
|
71
|
+
render: (args) => <Tool {...args} />,
|
|
72
|
+
} satisfies Meta<typeof Tool>;
|
|
73
|
+
|
|
74
|
+
export default meta;
|
|
75
|
+
type Story = StoryObj<typeof meta>;
|
|
76
|
+
|
|
77
|
+
const IMPORT = `import { Tool } from '@kitn.ai/ui';`;
|
|
78
|
+
const src = (code: string) => ({
|
|
79
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
/** Interactive playground — edit the `toolPart` object to explore every state. */
|
|
83
|
+
export const Playground: Story = {
|
|
84
|
+
...src(`<Tool
|
|
85
|
+
toolPart={{
|
|
86
|
+
type: 'search_documents',
|
|
87
|
+
state: 'output-available',
|
|
88
|
+
input: { query: 'SolidJS reactive primitives', limit: 10 },
|
|
89
|
+
output: { results: [{ title: 'Signals', score: 0.95 }] },
|
|
90
|
+
toolCallId: 'call_abc123',
|
|
91
|
+
}}
|
|
92
|
+
defaultOpen
|
|
93
|
+
/>`),
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const Processing: Story = {
|
|
97
|
+
args: { toolPart: streamingPart, defaultOpen: true },
|
|
98
|
+
...src(`<Tool
|
|
99
|
+
toolPart={{
|
|
100
|
+
type: 'search_documents',
|
|
101
|
+
state: 'input-streaming',
|
|
102
|
+
input: { query: 'SolidJS reactive primitives' },
|
|
103
|
+
toolCallId: 'call_abc123',
|
|
104
|
+
}}
|
|
105
|
+
defaultOpen
|
|
106
|
+
/>`),
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export const Ready: Story = {
|
|
110
|
+
args: { toolPart: readyPart, defaultOpen: true },
|
|
111
|
+
...src(`<Tool
|
|
112
|
+
toolPart={{
|
|
113
|
+
type: 'search_documents',
|
|
114
|
+
state: 'input-available',
|
|
115
|
+
input: { query: 'SolidJS reactive primitives', limit: 10 },
|
|
116
|
+
toolCallId: 'call_abc123',
|
|
117
|
+
}}
|
|
118
|
+
defaultOpen
|
|
119
|
+
/>`),
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export const Completed: Story = {
|
|
123
|
+
args: { toolPart: completedPart, defaultOpen: true },
|
|
124
|
+
...src(`<Tool
|
|
125
|
+
toolPart={{
|
|
126
|
+
type: 'search_documents',
|
|
127
|
+
state: 'output-available',
|
|
128
|
+
input: { query: 'SolidJS reactive primitives', limit: 10 },
|
|
129
|
+
output: { results: [{ title: 'Signals', score: 0.95 }, { title: 'Effects', score: 0.87 }] },
|
|
130
|
+
toolCallId: 'call_abc123',
|
|
131
|
+
}}
|
|
132
|
+
defaultOpen
|
|
133
|
+
/>`),
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export const Error: Story = {
|
|
137
|
+
args: { toolPart: errorPart, defaultOpen: true },
|
|
138
|
+
...src(`<Tool
|
|
139
|
+
toolPart={{
|
|
140
|
+
type: 'search_documents',
|
|
141
|
+
state: 'output-error',
|
|
142
|
+
input: { query: 'SolidJS reactive primitives' },
|
|
143
|
+
errorText: 'Connection timeout: unable to reach the search service after 30 seconds.',
|
|
144
|
+
toolCallId: 'call_abc123',
|
|
145
|
+
}}
|
|
146
|
+
defaultOpen
|
|
147
|
+
/>`),
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export const Collapsed: Story = {
|
|
151
|
+
args: { toolPart: completedPart, defaultOpen: false },
|
|
152
|
+
...src(`<Tool toolPart={toolPart} />`),
|
|
153
|
+
};
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { type JSX, splitProps, createSignal, Show, For } from 'solid-js';
|
|
2
|
+
import { cn } from '../utils/cn';
|
|
3
|
+
import { Collapsible, CollapsibleTrigger, CollapsibleContent } from '../ui/collapsible';
|
|
4
|
+
import { Button } from '../ui/button';
|
|
5
|
+
import { CheckCircle, ChevronDown, Loader2, Settings, XCircle } from 'lucide-solid';
|
|
6
|
+
|
|
7
|
+
export interface ToolPart {
|
|
8
|
+
type: string;
|
|
9
|
+
state: 'input-streaming' | 'input-available' | 'output-available' | 'output-error';
|
|
10
|
+
input?: Record<string, unknown>;
|
|
11
|
+
output?: Record<string, unknown>;
|
|
12
|
+
toolCallId?: string;
|
|
13
|
+
errorText?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ToolProps {
|
|
17
|
+
toolPart: ToolPart;
|
|
18
|
+
defaultOpen?: boolean;
|
|
19
|
+
class?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function formatValue(value: unknown): string {
|
|
23
|
+
if (value === null) return 'null';
|
|
24
|
+
if (value === undefined) return 'undefined';
|
|
25
|
+
if (typeof value === 'string') return value;
|
|
26
|
+
if (typeof value === 'object') return JSON.stringify(value, null, 2);
|
|
27
|
+
return String(value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function ToolStateIcon(props: { state: ToolPart['state'] }) {
|
|
31
|
+
return (
|
|
32
|
+
<>
|
|
33
|
+
<Show when={props.state === 'input-streaming'}>
|
|
34
|
+
<Loader2 class="size-4 animate-spin text-blue-500" />
|
|
35
|
+
</Show>
|
|
36
|
+
<Show when={props.state === 'input-available'}>
|
|
37
|
+
<Settings class="size-4 text-orange-500" />
|
|
38
|
+
</Show>
|
|
39
|
+
<Show when={props.state === 'output-available'}>
|
|
40
|
+
<CheckCircle class="size-4 text-green-500" />
|
|
41
|
+
</Show>
|
|
42
|
+
<Show when={props.state === 'output-error'}>
|
|
43
|
+
<XCircle class="size-4 text-red-500" />
|
|
44
|
+
</Show>
|
|
45
|
+
</>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Status chips: a hue as text over a 15% translucent fill of the same hue
|
|
50
|
+
// (mirroring the inline-code chip). The TEXT color comes from a theme token
|
|
51
|
+
// (--color-tool-*) whose light value is darkened so it reaches WCAG AA (4.5:1)
|
|
52
|
+
// on the faint fill, while dark mode keeps a brighter hue for AA on the dark
|
|
53
|
+
// surface — both modes resolve via the token's `.dark` override. The FILL keeps
|
|
54
|
+
// a fixed bright hue so the chip's colored tint looks the same in both modes.
|
|
55
|
+
const STATE_TOKEN: Record<ToolPart['state'], string> = {
|
|
56
|
+
'input-streaming': 'var(--color-tool-blue)',
|
|
57
|
+
'input-available': 'var(--color-tool-amber)',
|
|
58
|
+
'output-available': 'var(--color-tool-green)',
|
|
59
|
+
'output-error': 'var(--color-tool-red)',
|
|
60
|
+
};
|
|
61
|
+
const STATE_FILL: Record<ToolPart['state'], string> = {
|
|
62
|
+
'input-streaming': 'hsl(217 91% 60%)', // blue
|
|
63
|
+
'input-available': 'hsl(38 92% 50%)', // amber
|
|
64
|
+
'output-available': 'hsl(142 71% 45%)', // green
|
|
65
|
+
'output-error': 'hsl(0 84% 60%)', // red
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
function stateChip(state: ToolPart['state']): JSX.CSSProperties {
|
|
69
|
+
return {
|
|
70
|
+
color: STATE_TOKEN[state],
|
|
71
|
+
background: `color-mix(in oklab, ${STATE_FILL[state]} 15%, transparent)`,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function ToolStateBadge(props: { state: ToolPart['state'] }) {
|
|
76
|
+
const baseClasses = 'px-2 py-1 rounded-full text-xs font-medium';
|
|
77
|
+
return (
|
|
78
|
+
<>
|
|
79
|
+
<Show when={props.state === 'input-streaming'}>
|
|
80
|
+
<span class={baseClasses} style={stateChip('input-streaming')}>
|
|
81
|
+
Processing
|
|
82
|
+
</span>
|
|
83
|
+
</Show>
|
|
84
|
+
<Show when={props.state === 'input-available'}>
|
|
85
|
+
<span class={baseClasses} style={stateChip('input-available')}>
|
|
86
|
+
Ready
|
|
87
|
+
</span>
|
|
88
|
+
</Show>
|
|
89
|
+
<Show when={props.state === 'output-available'}>
|
|
90
|
+
<span class={baseClasses} style={stateChip('output-available')}>
|
|
91
|
+
Completed
|
|
92
|
+
</span>
|
|
93
|
+
</Show>
|
|
94
|
+
<Show when={props.state === 'output-error'}>
|
|
95
|
+
<span class={baseClasses} style={stateChip('output-error')}>
|
|
96
|
+
Error
|
|
97
|
+
</span>
|
|
98
|
+
</Show>
|
|
99
|
+
</>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function Tool(props: ToolProps) {
|
|
104
|
+
const [local, rest] = splitProps(props, ['toolPart', 'defaultOpen', 'class']);
|
|
105
|
+
const [isOpen, setIsOpen] = createSignal(local.defaultOpen ?? false);
|
|
106
|
+
|
|
107
|
+
const state = () => local.toolPart.state;
|
|
108
|
+
const input = () => local.toolPart.input;
|
|
109
|
+
const output = () => local.toolPart.output;
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<div class={cn('mt-3 overflow-hidden rounded-lg bg-muted/30', local.class)}>
|
|
113
|
+
<Collapsible open={isOpen()} onOpenChange={setIsOpen}>
|
|
114
|
+
<CollapsibleTrigger
|
|
115
|
+
as={(triggerProps: JSX.HTMLAttributes<HTMLButtonElement>) => (
|
|
116
|
+
<Button
|
|
117
|
+
variant="ghost"
|
|
118
|
+
class="h-auto w-full justify-between rounded-b-none px-3 py-2 font-normal"
|
|
119
|
+
{...triggerProps}
|
|
120
|
+
>
|
|
121
|
+
<div class="flex items-center gap-2">
|
|
122
|
+
<ToolStateIcon state={state()} />
|
|
123
|
+
<span class="font-mono text-sm font-medium">{local.toolPart.type}</span>
|
|
124
|
+
<ToolStateBadge state={state()} />
|
|
125
|
+
</div>
|
|
126
|
+
<ChevronDown class={cn('size-4 transition-transform', isOpen() && 'rotate-180')} />
|
|
127
|
+
</Button>
|
|
128
|
+
)}
|
|
129
|
+
/>
|
|
130
|
+
<CollapsibleContent
|
|
131
|
+
class="data-[state=closed]:animate-collapsible-up data-[state=open]:animate-collapsible-down overflow-hidden"
|
|
132
|
+
>
|
|
133
|
+
<div class="space-y-3 p-3">
|
|
134
|
+
<Show when={input() && Object.keys(input()!).length > 0}>
|
|
135
|
+
<div>
|
|
136
|
+
<h4 class="text-muted-foreground mb-2 text-sm font-medium">Input</h4>
|
|
137
|
+
<div class="rounded bg-muted/50 p-2 font-mono text-sm">
|
|
138
|
+
<For each={Object.entries(input()!)}>
|
|
139
|
+
{([key, value]) => (
|
|
140
|
+
<div class="mb-1">
|
|
141
|
+
<span class="text-muted-foreground">{key}:</span>{' '}
|
|
142
|
+
<span>{formatValue(value)}</span>
|
|
143
|
+
</div>
|
|
144
|
+
)}
|
|
145
|
+
</For>
|
|
146
|
+
</div>
|
|
147
|
+
</div>
|
|
148
|
+
</Show>
|
|
149
|
+
|
|
150
|
+
<Show when={output()}>
|
|
151
|
+
<div>
|
|
152
|
+
<h4 class="text-muted-foreground mb-2 text-sm font-medium">Output</h4>
|
|
153
|
+
<div tabindex={0} class="max-h-60 overflow-auto rounded bg-muted/50 p-2 font-mono text-sm">
|
|
154
|
+
<pre class="whitespace-pre-wrap">{formatValue(output())}</pre>
|
|
155
|
+
</div>
|
|
156
|
+
</div>
|
|
157
|
+
</Show>
|
|
158
|
+
|
|
159
|
+
<Show when={state() === 'output-error' && local.toolPart.errorText}>
|
|
160
|
+
<div>
|
|
161
|
+
<h4 class="mb-2 text-sm font-medium text-red-600 dark:text-red-400">Error</h4>
|
|
162
|
+
<div class="rounded bg-red-500/10 p-2 text-sm">
|
|
163
|
+
{local.toolPart.errorText}
|
|
164
|
+
</div>
|
|
165
|
+
</div>
|
|
166
|
+
</Show>
|
|
167
|
+
|
|
168
|
+
<Show when={state() === 'input-streaming'}>
|
|
169
|
+
<div class="text-muted-foreground text-sm">Processing tool call...</div>
|
|
170
|
+
</Show>
|
|
171
|
+
|
|
172
|
+
<Show when={local.toolPart.toolCallId}>
|
|
173
|
+
<div class="text-muted-foreground pt-2 text-xs">
|
|
174
|
+
<span class="font-mono">Call ID: {local.toolPart.toolCallId}</span>
|
|
175
|
+
</div>
|
|
176
|
+
</Show>
|
|
177
|
+
</div>
|
|
178
|
+
</CollapsibleContent>
|
|
179
|
+
</Collapsible>
|
|
180
|
+
</div>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export { Tool };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Shared resolution controller for interactive cards. Precedence:
|
|
2
|
+
// props.resolution (host-driven / re-hydrated) > local optimistic flip > none
|
|
3
|
+
// A new `data` identity clears the local flip (a fresh card definition is interactive
|
|
4
|
+
// again), but an explicit prop keeps it resolved. `isOptimistic` is true only for a
|
|
5
|
+
// flip made this session (used to announce via role="status"; silent on re-hydrate).
|
|
6
|
+
import { createSignal, createMemo, createEffect, on, type Accessor } from 'solid-js';
|
|
7
|
+
import type { CardResolution } from '../primitives/card-contract';
|
|
8
|
+
|
|
9
|
+
export interface ResolutionController {
|
|
10
|
+
resolution: Accessor<CardResolution | undefined>;
|
|
11
|
+
isResolved: Accessor<boolean>;
|
|
12
|
+
isOptimistic: Accessor<boolean>;
|
|
13
|
+
setLocal: (r: CardResolution) => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function useCardResolution(opts: {
|
|
17
|
+
prop: Accessor<CardResolution | undefined>;
|
|
18
|
+
data: Accessor<unknown>;
|
|
19
|
+
}): ResolutionController {
|
|
20
|
+
const [local, setLocal] = createSignal<CardResolution | undefined>(undefined);
|
|
21
|
+
// Reset the optimistic flip when a NEW data identity arrives (deferred so mount
|
|
22
|
+
// doesn't clobber an initial prop). The prop still wins via the memo below.
|
|
23
|
+
createEffect(on(opts.data, () => setLocal(undefined), { defer: true }));
|
|
24
|
+
const resolution = createMemo(() => opts.prop() ?? local());
|
|
25
|
+
const isResolved = createMemo(() => resolution() !== undefined);
|
|
26
|
+
const isOptimistic = createMemo(() => opts.prop() === undefined && local() !== undefined);
|
|
27
|
+
return { resolution, isResolved, isOptimistic, setLocal };
|
|
28
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { fn } from 'storybook/test';
|
|
3
|
+
import { VoiceInput } from './voice-input';
|
|
4
|
+
import { componentDescription } from '../stories/docs/element-controls';
|
|
5
|
+
|
|
6
|
+
/** Sample transcription handler — resolves the recorded audio to text. */
|
|
7
|
+
const transcribe = async (_audio: Blob): Promise<string> => {
|
|
8
|
+
await new Promise((r) => setTimeout(r, 1200));
|
|
9
|
+
return 'Hello from the microphone';
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const meta = {
|
|
13
|
+
title: 'Solid (Advanced)/Elements/VoiceInput',
|
|
14
|
+
component: VoiceInput,
|
|
15
|
+
tags: ['autodocs'],
|
|
16
|
+
parameters: {
|
|
17
|
+
layout: 'padded',
|
|
18
|
+
docs: {
|
|
19
|
+
controls: { exclude: ['use:eventListener'] },
|
|
20
|
+
description: componentDescription([
|
|
21
|
+
'A microphone button that records audio, shows recording (pulse rings) and processing (spinner) states, then hands the audio off for transcription.',
|
|
22
|
+
'**When to use:** to let users dictate input by voice instead of typing — speech-to-text for the prompt field.',
|
|
23
|
+
'**How to use:** provide `onTranscribe(audio)` returning a `Promise<string>` (your STT call) and `onTranscription(text)` to receive the result. Click toggles recording; transcription runs automatically on stop. Set `disabled` to block input.',
|
|
24
|
+
'**Placement:** inside the prompt input action bar, next to send and other input actions.',
|
|
25
|
+
]),
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
argTypes: {
|
|
29
|
+
disabled: {
|
|
30
|
+
control: 'boolean',
|
|
31
|
+
description: 'Disables the button (also disabled while transcribing).',
|
|
32
|
+
table: { defaultValue: { summary: 'false' } },
|
|
33
|
+
},
|
|
34
|
+
class: {
|
|
35
|
+
control: 'text',
|
|
36
|
+
description: 'Additional CSS classes for the container.',
|
|
37
|
+
},
|
|
38
|
+
onTranscribe: {
|
|
39
|
+
action: 'transcribe',
|
|
40
|
+
description: 'Receives the recorded audio `Blob` and must resolve to the transcribed text.',
|
|
41
|
+
table: { category: 'Events' },
|
|
42
|
+
},
|
|
43
|
+
onTranscription: {
|
|
44
|
+
action: 'transcription',
|
|
45
|
+
description: 'Called with the final transcribed text (trimmed, non-empty).',
|
|
46
|
+
table: { category: 'Events' },
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
args: {
|
|
50
|
+
disabled: false,
|
|
51
|
+
onTranscribe: transcribe,
|
|
52
|
+
onTranscription: fn(),
|
|
53
|
+
},
|
|
54
|
+
render: (args) => <VoiceInput {...args} />,
|
|
55
|
+
} satisfies Meta<typeof VoiceInput>;
|
|
56
|
+
|
|
57
|
+
export default meta;
|
|
58
|
+
type Story = StoryObj<typeof meta>;
|
|
59
|
+
|
|
60
|
+
const IMPORT = `import { VoiceInput } from '@kitn.ai/ui';`;
|
|
61
|
+
const src = (code: string) => ({
|
|
62
|
+
parameters: { docs: { source: { code: `${IMPORT}\n\n${code}`, language: 'tsx' } } },
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
/** Interactive playground — click the mic to record (requires mic permission). */
|
|
66
|
+
export const Playground: Story = {
|
|
67
|
+
...src(`<VoiceInput
|
|
68
|
+
onTranscribe={async (audio) => {
|
|
69
|
+
const res = await transcribeAudio(audio); // your STT call
|
|
70
|
+
return res.text;
|
|
71
|
+
}}
|
|
72
|
+
onTranscription={(text) => setInput((v) => v + text)}
|
|
73
|
+
/>`),
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const Disabled: Story = {
|
|
77
|
+
args: { disabled: true },
|
|
78
|
+
...src(`<VoiceInput
|
|
79
|
+
disabled
|
|
80
|
+
onTranscribe={transcribe}
|
|
81
|
+
onTranscription={(text) => setInput(text)}
|
|
82
|
+
/>`),
|
|
83
|
+
};
|