@kitnai/chat 0.6.0 → 0.8.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 -9
- package/dist/custom-elements.json +1676 -881
- package/dist/kitn-chat.es.js +36 -36
- package/dist/llms/llms-full.txt +316 -155
- package/dist/llms/llms.txt +18 -18
- package/dist/schemas/card-envelope.schema.json +14 -0
- package/dist/schemas/card-event.schema.json +12 -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/task-list.result.schema.json +16 -0
- package/dist/schemas/task-list.schema.json +78 -0
- package/dist/theme.tokens.css +65 -65
- package/dist/tsx-B8rCNbgL.js +1 -0
- package/dist/typescript-RycA9KXf.js +1 -0
- package/frameworks/react/index.tsx +382 -193
- package/frameworks/react/runtime.tsx +2 -2
- package/llms-full.txt +316 -155
- package/llms.txt +18 -18
- package/package.json +5 -2
- package/src/components/artifact.stories.tsx +138 -0
- package/src/components/artifact.tsx +581 -0
- package/src/components/attachments.stories.tsx +7 -8
- package/src/components/attachments.tsx +2 -2
- package/src/components/card.tsx +110 -0
- package/src/components/chain-of-thought.stories.tsx +7 -8
- package/src/components/chat-container.stories.tsx +7 -8
- package/src/components/chat-container.tsx +4 -0
- package/src/components/checkpoint.stories.tsx +7 -8
- package/src/components/code-block.stories.tsx +8 -9
- package/src/components/component-meta.json +3411 -0
- package/src/components/confirm-card.stories.tsx +74 -0
- package/src/components/confirm-card.tsx +299 -0
- package/src/components/context.stories.tsx +7 -8
- package/src/components/conversation-item.stories.tsx +7 -8
- package/src/components/conversation-item.tsx +2 -2
- package/src/components/conversation-list.stories.tsx +7 -8
- package/src/components/conversation-list.tsx +1 -1
- package/src/components/embed.tsx +196 -0
- package/src/components/empty.stories.tsx +8 -9
- package/src/components/feedback-bar.stories.tsx +7 -8
- package/src/components/file-tree.stories.tsx +73 -0
- package/src/components/file-tree.tsx +383 -0
- package/src/components/file-upload.stories.tsx +7 -8
- package/src/components/form-widgets.tsx +461 -0
- package/src/components/form.tsx +796 -0
- package/src/components/image.stories.tsx +7 -8
- package/src/components/link-card.tsx +194 -0
- package/src/components/loader.stories.tsx +7 -8
- package/src/components/markdown.stories.tsx +7 -8
- package/src/components/message-narrow.stories.tsx +12 -13
- package/src/components/message-skills.stories.tsx +16 -17
- package/src/components/message.stories.tsx +17 -18
- package/src/components/model-switcher.stories.tsx +7 -8
- package/src/components/prompt-input.stories.tsx +8 -9
- package/src/components/prompt-suggestion.stories.tsx +7 -8
- package/src/components/prompt-suggestion.tsx +3 -3
- package/src/components/reasoning.stories.tsx +7 -8
- package/src/components/scroll-button.stories.tsx +7 -8
- package/src/components/slash-command.stories.tsx +8 -9
- package/src/components/slash-command.tsx +2 -2
- package/src/components/source.stories.tsx +7 -8
- package/src/components/source.tsx +1 -1
- package/src/components/task-list-card.stories.tsx +78 -0
- package/src/components/task-list-card.tsx +388 -0
- package/src/components/text-shimmer.stories.tsx +7 -8
- package/src/components/thinking-bar.stories.tsx +7 -8
- package/src/components/tool.stories.tsx +7 -8
- package/src/components/tool.tsx +2 -2
- package/src/components/voice-input.stories.tsx +7 -8
- package/src/elements/artifact.stories.tsx +291 -0
- package/src/elements/artifact.tsx +72 -0
- package/src/elements/{kitn-attachments.stories.tsx → attachments.stories.tsx} +11 -11
- package/src/elements/attachments.tsx +4 -4
- package/src/elements/card.stories.tsx +118 -0
- package/src/elements/card.tsx +40 -0
- package/src/elements/catalog.stories.tsx +491 -0
- package/src/elements/{kitn-chain-of-thought.stories.tsx → chain-of-thought.stories.tsx} +13 -13
- package/src/elements/chain-of-thought.tsx +3 -3
- package/src/elements/{kitn-chat-scope-picker.stories.tsx → chat-scope-picker.stories.tsx} +10 -10
- package/src/elements/chat-scope-picker.tsx +4 -4
- package/src/elements/{kitn-chat-workspace.stories.tsx → chat-workspace.stories.tsx} +71 -29
- package/src/elements/chat-workspace.tsx +29 -3
- package/src/elements/{kitn-chat.stories.tsx → chat.stories.tsx} +61 -16
- package/src/elements/chat.tsx +23 -2
- package/src/elements/{kitn-checkpoint.stories.tsx → checkpoint.stories.tsx} +11 -11
- package/src/elements/checkpoint.tsx +4 -4
- package/src/elements/{kitn-code-block.stories.tsx → code-block.stories.tsx} +10 -10
- package/src/elements/code-block.tsx +3 -3
- package/src/elements/compiled.css +1 -1
- package/src/elements/composed-shell.stories.tsx +316 -0
- package/src/elements/confirm-card.stories.tsx +186 -0
- package/src/elements/confirm-card.tsx +45 -0
- package/src/elements/{kitn-context-meter.stories.tsx → context-meter.stories.tsx} +10 -10
- package/src/elements/context-meter.tsx +3 -3
- package/src/elements/{kitn-conversation-list.stories.tsx → conversation-list.stories.tsx} +35 -22
- package/src/elements/conversation-list.tsx +11 -2
- package/src/elements/css.ts +1 -1
- package/src/elements/define.tsx +10 -10
- package/src/elements/element-meta.json +2649 -0
- package/src/elements/element-types.d.ts +251 -125
- package/src/elements/embed.stories.tsx +197 -0
- package/src/elements/embed.tsx +35 -0
- package/src/elements/{kitn-empty.stories.tsx → empty.stories.tsx} +12 -12
- package/src/elements/empty.tsx +3 -3
- package/src/elements/{kitn-feedback-bar.stories.tsx → feedback-bar.stories.tsx} +11 -11
- package/src/elements/feedback-bar.tsx +4 -4
- package/src/elements/file-tree.stories.tsx +133 -0
- package/src/elements/file-tree.tsx +52 -0
- package/src/elements/{kitn-file-upload.stories.tsx → file-upload.stories.tsx} +12 -12
- package/src/elements/file-upload.tsx +4 -4
- package/src/elements/form.stories.tsx +204 -0
- package/src/elements/form.tsx +37 -0
- package/src/elements/{kitn-image.stories.tsx → image.stories.tsx} +10 -10
- package/src/elements/image.tsx +3 -3
- package/src/elements/link-card.stories.tsx +193 -0
- package/src/elements/link-card.tsx +34 -0
- package/src/elements/{kitn-loader.stories.tsx → loader.stories.tsx} +11 -11
- package/src/elements/loader.tsx +3 -3
- package/src/elements/{kitn-markdown.stories.tsx → markdown.stories.tsx} +10 -10
- package/src/elements/markdown.tsx +3 -3
- package/src/elements/{kitn-message-skills.stories.tsx → message-skills.stories.tsx} +10 -10
- package/src/elements/message-skills.tsx +3 -3
- package/src/elements/{kitn-message.stories.tsx → message.stories.tsx} +12 -12
- package/src/elements/message.tsx +5 -5
- package/src/elements/{kitn-model-switcher.stories.tsx → model-switcher.stories.tsx} +10 -10
- package/src/elements/model-switcher.tsx +5 -5
- package/src/elements/{kitn-prompt-input.stories.tsx → prompt-input.stories.tsx} +41 -19
- package/src/elements/prompt-input.tsx +5 -5
- package/src/elements/{kitn-prompt-suggestions.stories.tsx → prompt-suggestions.stories.tsx} +13 -13
- package/src/elements/prompt-suggestions.tsx +4 -4
- package/src/elements/{kitn-reasoning.stories.tsx → reasoning.stories.tsx} +10 -10
- package/src/elements/reasoning.tsx +4 -4
- package/src/elements/register.ts +11 -1
- package/src/elements/resizable.stories.tsx +200 -0
- package/src/elements/resizable.tsx +264 -0
- package/src/elements/{kitn-response-stream.stories.tsx → response-stream.stories.tsx} +10 -10
- package/src/elements/response-stream.tsx +4 -4
- package/src/elements/{kitn-source-list.stories.tsx → source-list.stories.tsx} +11 -11
- package/src/elements/{kitn-source.stories.tsx → source.stories.tsx} +12 -12
- package/src/elements/source.tsx +5 -5
- package/src/elements/styles.css +140 -1
- package/src/elements/task-list-card.stories.tsx +194 -0
- package/src/elements/task-list-card.tsx +40 -0
- package/src/elements/{kitn-text-shimmer.stories.tsx → text-shimmer.stories.tsx} +10 -10
- package/src/elements/text-shimmer.tsx +3 -3
- package/src/elements/{kitn-thinking-bar.stories.tsx → thinking-bar.stories.tsx} +11 -11
- package/src/elements/thinking-bar.tsx +5 -5
- package/src/elements/{kitn-tool.stories.tsx → tool.stories.tsx} +10 -10
- package/src/elements/tool.tsx +3 -3
- package/src/elements/{kitn-voice-input.stories.tsx → voice-input.stories.tsx} +10 -10
- package/src/elements/voice-input.tsx +4 -4
- package/src/index.ts +94 -2
- package/src/primitives/card-contract.ts +60 -0
- package/src/primitives/card-host.tsx +35 -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/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/task-list.result.schema.json +16 -0
- package/src/primitives/card-schemas/task-list.schema.json +78 -0
- package/src/primitives/card-validate.ts +95 -0
- package/src/primitives/embed-providers.ts +254 -0
- package/src/primitives/highlighter.ts +4 -0
- package/src/primitives/link-preview.ts +87 -0
- package/src/primitives/pdf-preview.ts +121 -0
- package/src/stories/chat-panel-layout.stories.tsx +2 -1
- package/src/stories/chat-scene.tsx +22 -21
- package/src/stories/checkpoint-restore.stories.tsx +10 -10
- package/src/stories/conversation-with-reasoning.stories.tsx +4 -4
- package/src/stories/conversation-with-sources.stories.tsx +7 -7
- package/src/stories/docs/Accessibility.mdx +2 -2
- package/src/stories/docs/ForAIAgents.mdx +3 -3
- package/src/stories/docs/GettingStarted.mdx +2 -2
- package/src/stories/docs/Installation.mdx +2 -2
- package/src/stories/docs/Integrations.mdx +29 -29
- package/src/stories/docs/Introduction.mdx +3 -3
- package/src/stories/docs/Theming.mdx +2 -2
- package/src/stories/docs/element-controls.ts +60 -0
- package/src/stories/docs/theme-editor/theme-editor.tsx +1 -0
- package/src/stories/examples/ChoosingComponents.mdx +94 -0
- package/src/stories/examples/sample-data.ts +79 -0
- package/src/stories/message-actions.stories.tsx +13 -13
- package/src/stories/pattern-centered-conversation.stories.tsx +3 -3
- package/src/stories/pattern-docked-widget.stories.tsx +1 -1
- package/src/stories/pattern-empty-state.stories.tsx +3 -3
- package/src/stories/prompt-input-variants.stories.tsx +13 -13
- package/src/stories/streaming-response.stories.tsx +3 -3
- package/src/stories/typography.stories.tsx +4 -4
- package/src/ui/avatar.stories.tsx +7 -8
- package/src/ui/badge.stories.tsx +7 -8
- package/src/ui/button.stories.tsx +8 -9
- package/src/ui/button.tsx +1 -0
- package/src/ui/collapsible.stories.tsx +6 -7
- package/src/ui/dropdown.stories.tsx +6 -7
- package/src/ui/hover-card.stories.tsx +6 -7
- package/src/ui/resizable.stories.tsx +74 -9
- package/src/ui/resizable.tsx +351 -71
- package/src/ui/scroll-area.stories.tsx +6 -7
- package/src/ui/scroll-area.tsx +3 -1
- package/src/ui/separator.stories.tsx +7 -8
- package/src/ui/skeleton.stories.tsx +7 -8
- package/src/ui/textarea.stories.tsx +6 -7
- package/src/ui/tooltip.stories.tsx +8 -9
- package/theme.css +65 -65
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { createSignal, onMount, For, type JSX } from 'solid-js';
|
|
3
|
+
import './register'; // side effect: registers the custom elements
|
|
4
|
+
import {
|
|
5
|
+
conversations,
|
|
6
|
+
context,
|
|
7
|
+
models,
|
|
8
|
+
slashCommands,
|
|
9
|
+
thread,
|
|
10
|
+
} from '../stories/examples/sample-data';
|
|
11
|
+
import type { ArtifactFile } from '../components/artifact';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Examples / Composed chat shell — THE headline. A real chat assembled from leaf
|
|
15
|
+
* `kc-*` components inside a `<kc-resizable>` layout, wired with sample data +
|
|
16
|
+
* event handlers in the story script. Paired with the `<kc-chat>` drop-in so the
|
|
17
|
+
* "batteries-included vs compose-your-own — when do I use which?" contrast is
|
|
18
|
+
* explicit. Both stories are source-visible (Show code).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
type AnyEl = HTMLElement & Record<string, unknown>;
|
|
22
|
+
/** Set JS properties (objects/arrays) on an element. */
|
|
23
|
+
const setProps = (el: HTMLElement, props: Record<string, unknown>) => {
|
|
24
|
+
for (const k in props) (el as AnyEl)[k] = props[k];
|
|
25
|
+
};
|
|
26
|
+
/** Set string/boolean attributes on an element. */
|
|
27
|
+
const setAttrs = (el: HTMLElement, a: Record<string, string | boolean>) => {
|
|
28
|
+
for (const k in a) {
|
|
29
|
+
const v = a[k];
|
|
30
|
+
if (v === false) el.removeAttribute(k);
|
|
31
|
+
else el.setAttribute(k, v === true ? '' : v);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const BASE = '/artifact-fixtures'; // served by .storybook/main.ts staticDirs
|
|
36
|
+
|
|
37
|
+
const ARTIFACT_FILES: ArtifactFile[] = [
|
|
38
|
+
{
|
|
39
|
+
path: 'index.html',
|
|
40
|
+
url: `${BASE}/index.html`,
|
|
41
|
+
type: 'html',
|
|
42
|
+
language: 'html',
|
|
43
|
+
code: '<!DOCTYPE html>\n<html><head><title>Starboard</title></head>\n<body><h1>Starboard</h1></body></html>',
|
|
44
|
+
},
|
|
45
|
+
{ path: 'css/site.css', url: `${BASE}/css/site.css`, type: 'other', language: 'css', code: 'body { font-family: system-ui; }' },
|
|
46
|
+
{ path: 'assets/logo.svg', url: `${BASE}/assets/logo.svg`, type: 'image' },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
/** A bordered frame the shell fills. */
|
|
50
|
+
function Frame(props: { children: JSX.Element; height?: string }) {
|
|
51
|
+
return (
|
|
52
|
+
<div
|
|
53
|
+
style={{
|
|
54
|
+
height: props.height ?? '560px',
|
|
55
|
+
width: '100%',
|
|
56
|
+
border: '1px solid var(--color-border, #e4e4e7)',
|
|
57
|
+
'border-radius': '12px',
|
|
58
|
+
overflow: 'hidden',
|
|
59
|
+
}}
|
|
60
|
+
>
|
|
61
|
+
{props.children}
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const meta = {
|
|
67
|
+
title: 'Examples/Composed chat shell',
|
|
68
|
+
parameters: {
|
|
69
|
+
layout: 'padded',
|
|
70
|
+
docs: {
|
|
71
|
+
description: {
|
|
72
|
+
component: [
|
|
73
|
+
'# Build your own chat',
|
|
74
|
+
'Two ways to ship a chat, side by side:',
|
|
75
|
+
'- **Compose your own** (`Composed shell`) — a `<kc-resizable>` laying out `<kc-conversations>` │ a chat column (`<kc-message>` list + `<kc-context>` meter + `<kc-prompt-input>` + `<kc-suggestions>`) │ `<kc-artifact>`. You own the data flow and event wiring; you control every panel. **Reach for this when the flagship doesn\'t fit** — custom layout, an inspector/canvas panel, bespoke header.',
|
|
76
|
+
'- **Batteries-included** (`Drop-in <kc-chat>`) — the whole chat surface in one tag. Set `messages`, listen for `submit`. **Reach for this for the 90% path** — a working chat in minutes.',
|
|
77
|
+
'Same leaf components underneath; the flagship just pre-wires them. See **Examples / Choosing components** for the full decision guide.',
|
|
78
|
+
'Both stories are source-visible — open **Show code** to read the exact composition + wiring.',
|
|
79
|
+
].join('\n\n'),
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
} satisfies Meta;
|
|
84
|
+
|
|
85
|
+
export default meta;
|
|
86
|
+
type Story = StoryObj;
|
|
87
|
+
|
|
88
|
+
// ── B1 · Composed shell ──────────────────────────────────────────────────────
|
|
89
|
+
|
|
90
|
+
const SHELL_SNIPPET = `<!-- Compose-your-own chat: a resizable shell built from leaf components -->
|
|
91
|
+
<kc-resizable orientation="horizontal" style="display:block;height:560px">
|
|
92
|
+
<!-- start: conversation list -->
|
|
93
|
+
<kc-resizable-item size="22%" min="180px" max="40%">
|
|
94
|
+
<kc-conversations id="list" style="display:block;height:100%"></kc-conversations>
|
|
95
|
+
</kc-resizable-item>
|
|
96
|
+
|
|
97
|
+
<!-- main: the chat column (scrolling messages + meter + composer) -->
|
|
98
|
+
<kc-resizable-item>
|
|
99
|
+
<div class="chat-col">
|
|
100
|
+
<div class="messages" id="messages"></div> <!-- <kc-message> per turn -->
|
|
101
|
+
<kc-context id="ctx"></kc-context>
|
|
102
|
+
<kc-suggestions id="suggs"></kc-suggestions>
|
|
103
|
+
<kc-prompt-input id="input" search voice></kc-prompt-input>
|
|
104
|
+
</div>
|
|
105
|
+
</kc-resizable-item>
|
|
106
|
+
|
|
107
|
+
<!-- end: artifact/preview panel (toggle with the 'hidden' attribute) -->
|
|
108
|
+
<kc-resizable-item size="32%" min="240px">
|
|
109
|
+
<kc-artifact id="artifact" style="display:block;height:100%"></kc-artifact>
|
|
110
|
+
</kc-resizable-item>
|
|
111
|
+
</kc-resizable>
|
|
112
|
+
|
|
113
|
+
<script type="module">
|
|
114
|
+
import '@kitnai/chat/elements';
|
|
115
|
+
|
|
116
|
+
// — data in via properties —
|
|
117
|
+
const list = document.getElementById('list');
|
|
118
|
+
list.conversations = [/* … */];
|
|
119
|
+
list.activeId = 'c1';
|
|
120
|
+
|
|
121
|
+
const ctx = document.getElementById('ctx');
|
|
122
|
+
ctx.context = { usedTokens: 48200, maxTokens: 200000 };
|
|
123
|
+
|
|
124
|
+
const suggs = document.getElementById('suggs');
|
|
125
|
+
suggs.suggestions = ['Summarize this thread', 'What changed in v0.3?'];
|
|
126
|
+
|
|
127
|
+
const input = document.getElementById('input');
|
|
128
|
+
input.slashCommands = [{ id: 'summarize', label: '/summarize', category: 'Actions' }];
|
|
129
|
+
|
|
130
|
+
const artifact = document.getElementById('artifact');
|
|
131
|
+
artifact.src = 'https://your-backend.example/artifacts/abc/index.html';
|
|
132
|
+
artifact.files = [{ path: 'index.html', url: '…', type: 'html', code: '…' }];
|
|
133
|
+
|
|
134
|
+
// render the message list yourself (you own the thread state)
|
|
135
|
+
const messages = document.getElementById('messages');
|
|
136
|
+
let thread = [/* { id, role, content, … } */];
|
|
137
|
+
const render = () => {
|
|
138
|
+
messages.innerHTML = '';
|
|
139
|
+
for (const m of thread) {
|
|
140
|
+
const el = document.createElement('kc-message');
|
|
141
|
+
el.message = m;
|
|
142
|
+
messages.append(el);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
render();
|
|
146
|
+
|
|
147
|
+
// — interactions out via events —
|
|
148
|
+
list.addEventListener('select', (e) => (list.activeId = e.detail.id));
|
|
149
|
+
suggs.addEventListener('select', (e) => (input.value = e.detail.value));
|
|
150
|
+
input.addEventListener('submit', (e) => {
|
|
151
|
+
thread = [...thread, { id: Date.now() + '', role: 'user', content: e.detail.value }];
|
|
152
|
+
render();
|
|
153
|
+
// …call your backend, append the assistant reply, re-render…
|
|
154
|
+
});
|
|
155
|
+
</script>`;
|
|
156
|
+
|
|
157
|
+
export const ComposedShell: Story = {
|
|
158
|
+
name: 'Composed shell',
|
|
159
|
+
render: () => {
|
|
160
|
+
const [messages, setMessages] = createSignal<Record<string, unknown>[]>(thread);
|
|
161
|
+
let list!: HTMLElement, ctx!: HTMLElement, suggs!: HTMLElement, input!: HTMLElement, artifact!: HTMLElement;
|
|
162
|
+
const msgRefs: HTMLElement[] = [];
|
|
163
|
+
|
|
164
|
+
onMount(() => {
|
|
165
|
+
setProps(list, { conversations, activeId: 'c1' });
|
|
166
|
+
list.addEventListener('select', (e) => ((list as AnyEl).activeId = (e as CustomEvent).detail.id));
|
|
167
|
+
setProps(ctx, { context });
|
|
168
|
+
setProps(suggs, { suggestions: ['Summarize this thread', 'What changed in v0.3?', 'Show me the layout code'] });
|
|
169
|
+
suggs.addEventListener('select', (e) => ((input as AnyEl).value = (e as CustomEvent).detail.value));
|
|
170
|
+
setProps(input, { slashCommands });
|
|
171
|
+
setAttrs(input, { search: true, voice: true, placeholder: 'Message the assistant…' });
|
|
172
|
+
input.addEventListener('submit', (e) => {
|
|
173
|
+
const value = (e as unknown as CustomEvent).detail.value as string;
|
|
174
|
+
if (!value) return;
|
|
175
|
+
setMessages((m) => [...m, { id: Date.now() + '', role: 'user', content: value }]);
|
|
176
|
+
(input as AnyEl).value = '';
|
|
177
|
+
setTimeout(() => {
|
|
178
|
+
setMessages((m) => [
|
|
179
|
+
...m,
|
|
180
|
+
{ id: Date.now() + 'a', role: 'assistant', content: 'Echo: ' + value, actions: ['copy'] },
|
|
181
|
+
]);
|
|
182
|
+
}, 500);
|
|
183
|
+
});
|
|
184
|
+
setProps(artifact, { src: `${BASE}/index.html`, files: ARTIFACT_FILES });
|
|
185
|
+
setAttrs(artifact, { 'iframe-title': 'Artifact preview' });
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Keep each <kc-message>'s `message` property in sync as the thread grows.
|
|
189
|
+
const syncMessages = () => {
|
|
190
|
+
const list = messages();
|
|
191
|
+
list.forEach((m, i) => {
|
|
192
|
+
if (msgRefs[i]) (msgRefs[i] as AnyEl).message = m;
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
return (
|
|
197
|
+
<Frame>
|
|
198
|
+
<kc-resizable orientation="horizontal">
|
|
199
|
+
<kc-resizable-item size="22%" min="180px" max="40%">
|
|
200
|
+
<kc-conversations ref={(e) => (list = e)} style={{ display: 'block', height: '100%' }} />
|
|
201
|
+
</kc-resizable-item>
|
|
202
|
+
|
|
203
|
+
<kc-resizable-item>
|
|
204
|
+
<div style={{ height: '100%', display: 'flex', 'flex-direction': 'column', 'min-height': '0' }}>
|
|
205
|
+
<div
|
|
206
|
+
style={{
|
|
207
|
+
flex: '1',
|
|
208
|
+
'min-height': '0',
|
|
209
|
+
'overflow-y': 'auto',
|
|
210
|
+
padding: '16px',
|
|
211
|
+
display: 'flex',
|
|
212
|
+
'flex-direction': 'column',
|
|
213
|
+
gap: '12px',
|
|
214
|
+
}}
|
|
215
|
+
>
|
|
216
|
+
<For each={messages()}>
|
|
217
|
+
{(m, i) => (
|
|
218
|
+
<kc-message
|
|
219
|
+
ref={(e) => {
|
|
220
|
+
msgRefs[i()] = e;
|
|
221
|
+
(e as AnyEl).message = m;
|
|
222
|
+
queueMicrotask(syncMessages);
|
|
223
|
+
}}
|
|
224
|
+
/>
|
|
225
|
+
)}
|
|
226
|
+
</For>
|
|
227
|
+
</div>
|
|
228
|
+
<div
|
|
229
|
+
style={{
|
|
230
|
+
'border-top': '1px solid var(--color-border, #e4e4e7)',
|
|
231
|
+
padding: '12px 16px',
|
|
232
|
+
display: 'flex',
|
|
233
|
+
'flex-direction': 'column',
|
|
234
|
+
gap: '8px',
|
|
235
|
+
}}
|
|
236
|
+
>
|
|
237
|
+
<kc-context ref={(e) => (ctx = e)} />
|
|
238
|
+
<kc-suggestions ref={(e) => (suggs = e)} />
|
|
239
|
+
<kc-prompt-input ref={(e) => (input = e)} />
|
|
240
|
+
</div>
|
|
241
|
+
</div>
|
|
242
|
+
</kc-resizable-item>
|
|
243
|
+
|
|
244
|
+
<kc-resizable-item size="32%" min="240px">
|
|
245
|
+
<kc-artifact ref={(e) => (artifact = e)} style={{ display: 'block', height: '100%' }} />
|
|
246
|
+
</kc-resizable-item>
|
|
247
|
+
</kc-resizable>
|
|
248
|
+
</Frame>
|
|
249
|
+
);
|
|
250
|
+
},
|
|
251
|
+
parameters: { docs: { source: { code: SHELL_SNIPPET, language: 'html' } } },
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
// ── B2 · Drop-in <kc-chat> ───────────────────────────────────────────────────
|
|
255
|
+
|
|
256
|
+
const DROPIN_SNIPPET = `<!-- Batteries-included: the whole chat surface in one tag -->
|
|
257
|
+
<kc-chat id="chat" chat-title="Assistant" search voice
|
|
258
|
+
style="display:block;height:560px"></kc-chat>
|
|
259
|
+
|
|
260
|
+
<script type="module">
|
|
261
|
+
import '@kitnai/chat/elements';
|
|
262
|
+
|
|
263
|
+
const chat = document.getElementById('chat');
|
|
264
|
+
chat.models = [{ id: 'opus', name: 'Claude Opus', provider: 'Anthropic' }];
|
|
265
|
+
chat.currentModel = 'opus';
|
|
266
|
+
chat.context = { usedTokens: 48200, maxTokens: 200000 };
|
|
267
|
+
chat.suggestions = ['Summarize this thread', 'What changed in v0.3?'];
|
|
268
|
+
chat.messages = [
|
|
269
|
+
{ id: '1', role: 'assistant', content: "Hi! I'm the drop-in <kc-chat>. Ask me anything.",
|
|
270
|
+
actions: ['copy', 'like', 'dislike'] },
|
|
271
|
+
];
|
|
272
|
+
|
|
273
|
+
chat.addEventListener('submit', (e) => {
|
|
274
|
+
chat.messages = [...chat.messages, { id: Date.now() + '', role: 'user', content: e.detail.value }];
|
|
275
|
+
chat.loading = true;
|
|
276
|
+
// …call your backend, then append the reply and clear loading…
|
|
277
|
+
});
|
|
278
|
+
chat.addEventListener('modelchange', (e) => (chat.currentModel = e.detail.modelId));
|
|
279
|
+
</script>`;
|
|
280
|
+
|
|
281
|
+
export const DropInChat: Story = {
|
|
282
|
+
name: 'Drop-in <kc-chat>',
|
|
283
|
+
render: () => {
|
|
284
|
+
let chat!: HTMLElement;
|
|
285
|
+
onMount(() => {
|
|
286
|
+
setProps(chat, {
|
|
287
|
+
models,
|
|
288
|
+
currentModel: 'opus',
|
|
289
|
+
context,
|
|
290
|
+
suggestions: ['Summarize this thread', 'What changed in v0.3?'],
|
|
291
|
+
messages: [
|
|
292
|
+
{ id: '1', role: 'assistant', content: "Hi! I'm the **drop-in** `<kc-chat>`. Ask me anything.", actions: ['copy', 'like', 'dislike'] },
|
|
293
|
+
],
|
|
294
|
+
});
|
|
295
|
+
setAttrs(chat, { 'chat-title': 'Assistant', search: true, voice: true });
|
|
296
|
+
chat.addEventListener('submit', (e) => {
|
|
297
|
+
const value = (e as unknown as CustomEvent).detail.value as string;
|
|
298
|
+
const cur = (chat as AnyEl).messages as unknown[];
|
|
299
|
+
(chat as AnyEl).messages = [...cur, { id: Date.now() + '', role: 'user', content: value }];
|
|
300
|
+
(chat as AnyEl).loading = true;
|
|
301
|
+
setTimeout(() => {
|
|
302
|
+
const cur2 = (chat as AnyEl).messages as unknown[];
|
|
303
|
+
(chat as AnyEl).messages = [...cur2, { id: Date.now() + 'a', role: 'assistant', content: 'Echo: ' + value, actions: ['copy'] }];
|
|
304
|
+
(chat as AnyEl).loading = false;
|
|
305
|
+
}, 600);
|
|
306
|
+
});
|
|
307
|
+
chat.addEventListener('modelchange', (e) => ((chat as AnyEl).currentModel = (e as CustomEvent).detail.modelId));
|
|
308
|
+
});
|
|
309
|
+
return (
|
|
310
|
+
<Frame>
|
|
311
|
+
<kc-chat ref={(e) => (chat = e)} style={{ display: 'block', height: '100%' }} />
|
|
312
|
+
</Frame>
|
|
313
|
+
);
|
|
314
|
+
},
|
|
315
|
+
parameters: { docs: { source: { code: DROPIN_SNIPPET, language: 'html' } } },
|
|
316
|
+
};
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
|
+
import { createSignal, onMount, type JSX } from 'solid-js';
|
|
3
|
+
import './confirm-card';
|
|
4
|
+
import { argTypesFor, specDescription } from '../stories/docs/element-controls';
|
|
5
|
+
import type { ConfirmCardData } from '../components/confirm-card';
|
|
6
|
+
import type { CardEvent } from '../primitives/card-contract';
|
|
7
|
+
|
|
8
|
+
declare module 'solid-js' {
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
10
|
+
namespace JSX {
|
|
11
|
+
interface IntrinsicElements {
|
|
12
|
+
'kc-confirm': JSX.HTMLAttributes<HTMLElement> & {
|
|
13
|
+
heading?: string;
|
|
14
|
+
'card-id'?: string;
|
|
15
|
+
ref?: (el: HTMLElement) => void;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type ConfirmEl = HTMLElement & { data?: ConfirmCardData };
|
|
22
|
+
|
|
23
|
+
function Frame(props: { children: JSX.Element }) {
|
|
24
|
+
return <div style={{ 'max-width': '460px' }}>{props.children}</div>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Mounts a <kc-confirm>, sets `.data`, logs the emitted CardEvent under the render. */
|
|
28
|
+
function ConfirmDemo(props: { def: ConfirmCardData; cardId: string; heading?: string }) {
|
|
29
|
+
const [log, setLog] = createSignal<CardEvent[]>([]);
|
|
30
|
+
let el: ConfirmEl | undefined;
|
|
31
|
+
onMount(() => {
|
|
32
|
+
if (!el) return;
|
|
33
|
+
el.data = props.def;
|
|
34
|
+
el.addEventListener('kc-card', (e) => {
|
|
35
|
+
const detail = (e as CustomEvent<CardEvent>).detail;
|
|
36
|
+
setLog((prev) => [...prev, detail]);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
return (
|
|
40
|
+
<Frame>
|
|
41
|
+
<div style={{ display: 'flex', 'flex-direction': 'column', gap: '12px' }}>
|
|
42
|
+
<kc-confirm ref={(e) => (el = e as ConfirmEl)} card-id={props.cardId} heading={props.heading} />
|
|
43
|
+
<pre
|
|
44
|
+
style={{
|
|
45
|
+
margin: 0,
|
|
46
|
+
'max-height': '180px',
|
|
47
|
+
overflow: 'auto',
|
|
48
|
+
background: 'var(--color-muted, #f4f4f5)',
|
|
49
|
+
'border-radius': '8px',
|
|
50
|
+
padding: '8px',
|
|
51
|
+
'font-size': '12px',
|
|
52
|
+
}}
|
|
53
|
+
>
|
|
54
|
+
{log().length === 0 ? '// emitted CardEvents appear here' : JSON.stringify(log(), null, 2)}
|
|
55
|
+
</pre>
|
|
56
|
+
</div>
|
|
57
|
+
</Frame>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const APPROVE: ConfirmCardData = {
|
|
62
|
+
body: 'This will apply 3 pending migrations to production. This cannot be undone.',
|
|
63
|
+
tone: 'warning',
|
|
64
|
+
actions: [
|
|
65
|
+
{ id: 'approve', label: 'Run migration', style: 'primary', default: true },
|
|
66
|
+
{ id: 'reject', label: 'Cancel' },
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const DESTRUCTIVE: ConfirmCardData = {
|
|
71
|
+
body: 'Permanently delete 12 files from the workspace? This cannot be undone.',
|
|
72
|
+
tone: 'danger',
|
|
73
|
+
actions: [
|
|
74
|
+
{ id: 'delete', label: 'Delete files', style: 'destructive', default: true },
|
|
75
|
+
{ id: 'cancel', label: 'Keep them' },
|
|
76
|
+
],
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const CHOICES: ConfirmCardData = {
|
|
80
|
+
heading: 'Where should I deploy?',
|
|
81
|
+
body: 'Pick a target environment for this build.',
|
|
82
|
+
actions: [
|
|
83
|
+
{ id: 'staging', label: 'Staging', default: true },
|
|
84
|
+
{ id: 'preview', label: 'Preview' },
|
|
85
|
+
{ id: 'prod', label: 'Production', style: 'primary' },
|
|
86
|
+
],
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const DISMISSIBLE: ConfirmCardData = {
|
|
90
|
+
body: 'Send the drafted email to the customer?',
|
|
91
|
+
dismissible: true,
|
|
92
|
+
actions: [
|
|
93
|
+
{ id: 'send', label: 'Send', style: 'primary', default: true },
|
|
94
|
+
{ id: 'edit', label: 'Edit first' },
|
|
95
|
+
],
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const HEADING_MAP: Record<string, string | undefined> = {
|
|
99
|
+
'card-approve': 'Run database migration?',
|
|
100
|
+
'card-delete': 'Delete files?',
|
|
101
|
+
'card-deploy': undefined,
|
|
102
|
+
'card-send': 'Send email?',
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const HTML_SNIPPET = (def: ConfirmCardData, cardId: string) => {
|
|
106
|
+
const heading = HEADING_MAP[cardId];
|
|
107
|
+
return `<kc-confirm${heading ? ` heading="${heading}"` : ''}></kc-confirm>
|
|
108
|
+
<script type="module">
|
|
109
|
+
import '@kitnai/chat/elements'; // registers the custom elements
|
|
110
|
+
|
|
111
|
+
const el = document.querySelector('kc-confirm');
|
|
112
|
+
// \`data\` is the CardEnvelope.data (set as a property).
|
|
113
|
+
el.data = ${JSON.stringify(def, null, 2)};
|
|
114
|
+
|
|
115
|
+
// Cards bubble ONE \`kc-card\` CustomEvent carrying a typed CardEvent.
|
|
116
|
+
el.addEventListener('kc-card', (e) => {
|
|
117
|
+
const ev = e.detail; // { kind:'action', cardId, action, payload? } | { kind:'dismiss', ... } | ...
|
|
118
|
+
if (ev.kind === 'action') console.log('chose', ev.action);
|
|
119
|
+
});
|
|
120
|
+
</script>`;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const meta = {
|
|
124
|
+
title: 'Generative UI/Cards/kc-confirm',
|
|
125
|
+
tags: ['autodocs'],
|
|
126
|
+
argTypes: argTypesFor('kc-confirm'),
|
|
127
|
+
parameters: {
|
|
128
|
+
layout: 'padded',
|
|
129
|
+
docs: {
|
|
130
|
+
description: specDescription('kc-confirm', [
|
|
131
|
+
"`<kc-confirm>` is a **named-intent approval** card (set via the `data` **property**): a title + body + a small set of action buttons. Activating an action emits the Card contract's **`action`** verb up a bubbling **`kc-card`** CustomEvent of `{ kind: 'action', cardId, action, payload? }`, then **resolves** the card (other actions disabled, the chosen one marked) so the same approval can't double-fire.",
|
|
132
|
+
'**Action styles:** `primary` (filled accent), `default` (outline), `destructive` (red/danger). A `tone:\'danger\'` and any destructive action add a warning icon + danger accent — never color alone. At most one action can be `default:true` (the keyboard default; gets focus only when `autofocus` is set, which is **off** by default to avoid focus-stealing mid-stream).',
|
|
133
|
+
'**Events** (all frozen Card-contract verbs): `ready` on mount, `action` on choice, `dismiss` for the optional close affordance (`dismissible:true`), `error` for a malformed definition (renders the inline `kc-card` error). It **never invents events**. The same shapes flow over the remote iframe transport unchanged.',
|
|
134
|
+
]),
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
} satisfies Meta;
|
|
138
|
+
|
|
139
|
+
export default meta;
|
|
140
|
+
type Story = StoryObj;
|
|
141
|
+
|
|
142
|
+
/** The canonical two-action approval (Approve / Reject). */
|
|
143
|
+
export const ApproveReject: Story = {
|
|
144
|
+
render: () => <ConfirmDemo def={APPROVE} cardId="card-approve" heading="Run database migration?" />,
|
|
145
|
+
parameters: { docs: { source: { code: HTML_SNIPPET(APPROVE, 'card-approve'), language: 'html' } } },
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/** A destructive action (`tone:'danger'` + `style:'destructive'`) — danger styling, no color-only cue. */
|
|
149
|
+
export const Destructive: Story = {
|
|
150
|
+
render: () => <ConfirmDemo def={DESTRUCTIVE} cardId="card-delete" heading="Delete files?" />,
|
|
151
|
+
parameters: { docs: { source: { code: HTML_SNIPPET(DESTRUCTIVE, 'card-delete'), language: 'html' } } },
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/** A small choice set (3 actions, one `default:true`). */
|
|
155
|
+
export const ChoiceSet: Story = {
|
|
156
|
+
render: () => <ConfirmDemo def={CHOICES} cardId="card-deploy" />,
|
|
157
|
+
parameters: { docs: { source: { code: HTML_SNIPPET(CHOICES, 'card-deploy'), language: 'html' } } },
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/** A dismissible approval (a close affordance emits the `dismiss` verb). */
|
|
161
|
+
export const Dismissible: Story = {
|
|
162
|
+
render: () => <ConfirmDemo def={DISMISSIBLE} cardId="card-send" heading="Send email?" />,
|
|
163
|
+
parameters: { docs: { source: { code: HTML_SNIPPET(DISMISSIBLE, 'card-send'), language: 'html' } } },
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
/** A malformed `data` (empty `actions`) → the inline error state + an `error` event. */
|
|
167
|
+
export const ErrorState: Story = {
|
|
168
|
+
render: () => <ConfirmDemo def={{ actions: [] } as unknown as ConfirmCardData} cardId="card-bad" />,
|
|
169
|
+
parameters: {
|
|
170
|
+
docs: {
|
|
171
|
+
source: {
|
|
172
|
+
code: `<kc-confirm></kc-confirm>
|
|
173
|
+
<script type="module">
|
|
174
|
+
import '@kitnai/chat/elements';
|
|
175
|
+
const el = document.querySelector('kc-confirm');
|
|
176
|
+
// No actions → inline error state + an \`error\` event.
|
|
177
|
+
el.data = { actions: [] };
|
|
178
|
+
el.addEventListener('kc-card', (e) => {
|
|
179
|
+
if (e.detail.kind === 'error') console.warn('confirm error:', e.detail.message);
|
|
180
|
+
});
|
|
181
|
+
</script>`,
|
|
182
|
+
language: 'html',
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { defineWebComponent } from './define';
|
|
2
|
+
import { ConfirmCard, type ConfirmCardData } from '../components/confirm-card';
|
|
3
|
+
|
|
4
|
+
interface Props extends Record<string, unknown> {
|
|
5
|
+
/** The confirm definition (the CardEnvelope.data). Set as a JS PROPERTY:
|
|
6
|
+
* `el.data = { body, tone, actions:[…] }`. Import `ConfirmCardData` from
|
|
7
|
+
* `@kitnai/chat` for the full shape. */
|
|
8
|
+
data?: Record<string, unknown>;
|
|
9
|
+
/** Stable card id correlating every emitted CardEvent. Attribute: `card-id`. */
|
|
10
|
+
cardId?: string;
|
|
11
|
+
/** Heading rendered in the card chrome (= CardEnvelope.title). Attribute: `heading`. */
|
|
12
|
+
heading?: string;
|
|
13
|
+
/** Focus the default action on mount (off by default — no focus-stealing).
|
|
14
|
+
* Attribute: `autofocus`. */
|
|
15
|
+
autofocus?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* `<kc-confirm>` — a named-intent **approval** card (set via the `data` property):
|
|
20
|
+
* a title + body + a small set of action buttons. Activating an action emits the
|
|
21
|
+
* Card contract's **`action`** verb up a bubbling **`kc-card`** CustomEvent
|
|
22
|
+
* (`{ kind:'action', cardId, action, payload }`) and resolves the card so the same
|
|
23
|
+
* approval can't double-fire. Also emits `ready` on mount, `dismiss` for the
|
|
24
|
+
* optional close affordance, and `error` for a malformed definition (inline error).
|
|
25
|
+
* Routes through a `CardProvider` when present, else the bubbling `kc-card` event.
|
|
26
|
+
* Isolated in Shadow DOM; theme-aware via the shared kit tokens.
|
|
27
|
+
*/
|
|
28
|
+
defineWebComponent<Props>(
|
|
29
|
+
'kc-confirm',
|
|
30
|
+
{
|
|
31
|
+
data: undefined,
|
|
32
|
+
cardId: undefined,
|
|
33
|
+
heading: undefined,
|
|
34
|
+
autofocus: false,
|
|
35
|
+
},
|
|
36
|
+
(props, { element, flag }) => (
|
|
37
|
+
<ConfirmCard
|
|
38
|
+
data={props.data as ConfirmCardData | undefined}
|
|
39
|
+
cardId={props.cardId ?? (element.id || 'kc-confirm')}
|
|
40
|
+
heading={props.heading}
|
|
41
|
+
autofocus={flag('autofocus')}
|
|
42
|
+
hostElement={element}
|
|
43
|
+
/>
|
|
44
|
+
),
|
|
45
|
+
);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
|
|
2
2
|
import { onMount } from 'solid-js';
|
|
3
3
|
import './register'; // side effect: registers the custom elements
|
|
4
|
+
import { argTypesFor, specDescription } from '../stories/docs/element-controls';
|
|
4
5
|
|
|
5
6
|
interface ContextUsage {
|
|
6
7
|
usedTokens: number;
|
|
@@ -17,7 +18,7 @@ declare module 'solid-js' {
|
|
|
17
18
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
18
19
|
namespace JSX {
|
|
19
20
|
interface IntrinsicElements {
|
|
20
|
-
'
|
|
21
|
+
'kc-context': JSX.HTMLAttributes<HTMLElement>;
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
}
|
|
@@ -32,19 +33,19 @@ const usage: ContextUsage = {
|
|
|
32
33
|
estimatedCost: 0.42,
|
|
33
34
|
};
|
|
34
35
|
|
|
35
|
-
/** Render `<
|
|
36
|
+
/** Render `<kc-context>` with the `context` set as a JS property. */
|
|
36
37
|
function MeterElement(props: { context: ContextUsage }) {
|
|
37
38
|
let el: (HTMLElement & { context?: ContextUsage }) | undefined;
|
|
38
39
|
onMount(() => {
|
|
39
40
|
if (el) el.context = props.context;
|
|
40
41
|
});
|
|
41
42
|
return (
|
|
42
|
-
<
|
|
43
|
+
<kc-context ref={(e) => (el = e as HTMLElement)} style={{ display: 'inline-block', padding: '40px' }} />
|
|
43
44
|
);
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
47
|
-
<
|
|
48
|
+
<kc-context id="ctx"></kc-context>
|
|
48
49
|
|
|
49
50
|
<script type="module">
|
|
50
51
|
import '@kitnai/chat/elements'; // registers the custom elements
|
|
@@ -58,19 +59,18 @@ const HTML_SNIPPET = `<!-- Works in any framework or plain HTML -->
|
|
|
58
59
|
</script>`;
|
|
59
60
|
|
|
60
61
|
const meta = {
|
|
61
|
-
title: 'Web Components/
|
|
62
|
+
title: 'Web Components/kc-context',
|
|
62
63
|
tags: ['autodocs'],
|
|
64
|
+
argTypes: argTypesFor('kc-context'),
|
|
63
65
|
parameters: {
|
|
64
66
|
layout: 'fullscreen',
|
|
65
67
|
docs: {
|
|
66
|
-
description:
|
|
67
|
-
|
|
68
|
-
'`<kitn-context-meter>` is the framework-agnostic **web component** for a token/context-window usage meter — a compact gauge with a hover-card breakdown (input / output / reasoning / cache + estimated cost) — isolated in **Shadow DOM**.',
|
|
68
|
+
description: specDescription('kc-context', [
|
|
69
|
+
'`<kc-context>` is the framework-agnostic **web component** for a token/context-window usage meter — a compact gauge with a hover-card breakdown (input / output / reasoning / cache + estimated cost) — isolated in **Shadow DOM**.',
|
|
69
70
|
'**When to use:** showing how much of the context window a conversation is using, typically in a chat header. In SolidJS, compose the `Context` primitives.',
|
|
70
71
|
"**How to use:** register once with `import '@kitnai/chat/elements'`, then set the `context` **property** with the usage object. Hover the meter to reveal the breakdown.",
|
|
71
72
|
'See the **Code** tab for HTML usage.',
|
|
72
|
-
]
|
|
73
|
-
},
|
|
73
|
+
]),
|
|
74
74
|
},
|
|
75
75
|
},
|
|
76
76
|
} satisfies Meta;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Show } from 'solid-js';
|
|
2
|
-
import {
|
|
2
|
+
import { defineWebComponent } from './define';
|
|
3
3
|
import {
|
|
4
4
|
Context,
|
|
5
5
|
ContextTrigger,
|
|
@@ -36,11 +36,11 @@ interface Props extends Record<string, unknown> {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* `<
|
|
39
|
+
* `<kc-context>` — a token/context-window usage meter with a hover-card
|
|
40
40
|
* breakdown (input/output/reasoning/cache + estimated cost). Data via the
|
|
41
41
|
* `context` property.
|
|
42
42
|
*/
|
|
43
|
-
|
|
43
|
+
defineWebComponent<Props>('kc-context', {
|
|
44
44
|
context: undefined,
|
|
45
45
|
}, (props) => (
|
|
46
46
|
<Show when={props.context}>
|