@kitn.ai/ui 0.15.1 → 0.17.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 +37 -13
- 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 +91 -0
- package/dist/components/checkpoint.d.ts +20 -0
- package/dist/components/choice-card.d.ts +78 -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/dismissed-stub.d.ts +22 -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 +111 -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-compare-types.d.ts +66 -0
- package/dist/components/response-compare.d.ts +51 -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 +72 -0
- package/dist/components/text-shimmer.d.ts +9 -0
- package/dist/components/thinking-bar.d.ts +10 -0
- package/dist/components/toast.d.ts +48 -0
- package/dist/components/tool.d.ts +16 -0
- package/dist/components/use-card-resolution.d.ts +16 -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/custom-elements.json +260 -11
- package/dist/elements/artifact.d.ts +1 -0
- package/dist/elements/artifact.js +1 -0
- package/dist/elements/attachments.d.ts +1 -0
- package/dist/elements/attachments.js +1 -0
- package/dist/elements/autoloader.d.ts +2 -0
- package/dist/elements/autoloader.js +1 -0
- package/dist/elements/card.d.ts +1 -0
- package/dist/elements/card.js +1 -0
- package/dist/elements/cards.d.ts +1 -0
- package/dist/elements/cards.js +1 -0
- package/dist/elements/chain-of-thought.d.ts +1 -0
- package/dist/elements/chain-of-thought.js +1 -0
- package/dist/elements/chat-scope-picker.d.ts +1 -0
- package/dist/elements/chat-scope-picker.js +1 -0
- package/dist/elements/chat-workspace.d.ts +1 -0
- package/dist/elements/chat-workspace.js +1 -0
- package/dist/elements/chat.d.ts +1 -0
- package/dist/elements/chat.js +1 -0
- package/dist/elements/checkpoint.d.ts +1 -0
- package/dist/elements/checkpoint.js +1 -0
- package/dist/elements/choice.d.ts +1 -0
- package/dist/elements/choice.js +1 -0
- package/dist/elements/chunks/Icon-D_Zmwmwh.js +1 -0
- package/dist/elements/chunks/action-icons-PVfIvcuG.js +1 -0
- package/dist/elements/chunks/attachments-Dp6vqtrc.js +1 -0
- package/dist/elements/chunks/bash-InADTalH.js +1 -0
- package/dist/elements/chunks/button-CKyYD9G4.js +1 -0
- package/dist/elements/chunks/card-Cjho-PYk.js +1 -0
- package/dist/elements/chunks/card-routing-C986KuUA.js +1 -0
- package/dist/elements/chunks/chat-thread-RT808iPf.js +1 -0
- package/dist/elements/chunks/check-CDYaMYrM.js +1 -0
- package/dist/elements/chunks/chevron-down-3SBiq8HF.js +1 -0
- package/dist/elements/chunks/chevron-right-k2UFlIVK.js +1 -0
- package/dist/elements/chunks/cn-Dogu6PbV.js +1 -0
- package/dist/elements/chunks/code-block-BYUmfFSd.js +1 -0
- package/dist/elements/chunks/collapsible-BiNwdOn6.js +1 -0
- package/dist/elements/chunks/context-18g6oi4J.js +1 -0
- package/dist/elements/chunks/conversation-list-D9Y0NVdo.js +1 -0
- package/dist/elements/chunks/core-AYMC6_lb.js +12 -0
- package/dist/elements/chunks/css-M7EaDHN_.js +1 -0
- package/dist/elements/chunks/default-input-CSAoYYMd.js +1 -0
- package/dist/elements/chunks/download-D8K0Je8r.js +1 -0
- package/dist/elements/chunks/dropdown-bUs2iTia.js +1 -0
- package/dist/elements/chunks/engine-javascript-vq0WuIJl.js +141 -0
- package/dist/elements/chunks/external-link-6mA0wxab.js +1 -0
- package/dist/elements/chunks/file-text-DnaYk3Dm.js +1 -0
- package/dist/elements/chunks/file-tree-CgtRLlxK.js +1 -0
- package/dist/elements/chunks/github-dark-dimmed-DUshB20C.js +1 -0
- package/dist/elements/chunks/github-light-JYsPkUQd.js +1 -0
- package/dist/elements/chunks/hover-card-CIGw62gP.js +1 -0
- package/dist/elements/chunks/html-CPZ3oZQ7.js +1 -0
- package/dist/elements/chunks/index-CTBEJeo6.js +1 -0
- package/dist/elements/chunks/javascript-C25yR2R2.js +1 -0
- package/dist/elements/chunks/json-DxJze_jm.js +1 -0
- package/dist/elements/chunks/link-BlGSeoPy.js +1 -0
- package/dist/elements/chunks/loader-DvhR4qa0.js +1 -0
- package/dist/elements/chunks/markdown-CMTGx9r8.js +64 -0
- package/dist/elements/chunks/message-CDZwXjhL.js +1 -0
- package/dist/elements/chunks/message-feedback-CYx81QiA.js +1 -0
- package/dist/elements/chunks/model-switcher-O_tUhoOT.js +1 -0
- package/dist/elements/chunks/overlay-DydXYMQW.js +1 -0
- package/dist/elements/chunks/prompt-suggestion-ldlWV5kd.js +1 -0
- package/dist/elements/chunks/reasoning-2PUnHlmr.js +1 -0
- package/dist/elements/chunks/resizable-B5WNbSeb.js +1 -0
- package/dist/elements/chunks/star-t9tI-P0q.js +1 -0
- package/dist/elements/chunks/store-C6rIooZz.js +1 -0
- package/dist/elements/chunks/svelte--5p79yCD.js +1 -0
- package/dist/elements/chunks/text-shimmer-uh9V_KUh.js +1 -0
- package/dist/elements/chunks/textarea-3nm6Ia9U.js +1 -0
- package/dist/elements/chunks/thumbs-up-BBtguGld.js +1 -0
- package/dist/elements/chunks/toast-store-D8cL3fWl.js +1 -0
- package/dist/elements/chunks/tool-GJ3vwp1U.js +1 -0
- package/dist/elements/chunks/tooltip-DwKAz4XR.js +1 -0
- package/dist/elements/chunks/triangle-alert-Ct1zt2JL.js +1 -0
- package/dist/elements/chunks/tsx-B8rCNbgL.js +1 -0
- package/dist/elements/chunks/typescript-RycA9KXf.js +1 -0
- package/dist/elements/chunks/use-card-resolution-D-_0Alzy.js +1 -0
- package/dist/elements/chunks/video-mVYiM99-.js +1 -0
- package/dist/elements/chunks/vue-BmIZj4XD.js +1 -0
- package/dist/elements/chunks/x-CzxL27Ch.js +1 -0
- package/dist/elements/code-block.d.ts +1 -0
- package/dist/elements/code-block.js +1 -0
- package/dist/elements/compare.d.ts +1 -0
- package/dist/elements/compare.js +1 -0
- package/dist/elements/confirm-card.d.ts +1 -0
- package/dist/elements/confirm-card.js +1 -0
- package/dist/elements/context-meter.d.ts +1 -0
- package/dist/elements/context-meter.js +1 -0
- package/dist/elements/conversation-list.d.ts +1 -0
- package/dist/elements/conversation-list.js +1 -0
- package/dist/elements/embed.d.ts +1 -0
- package/dist/elements/embed.js +1 -0
- package/dist/elements/empty.d.ts +1 -0
- package/dist/elements/empty.js +1 -0
- package/dist/elements/feedback-bar.d.ts +1 -0
- package/dist/elements/feedback-bar.js +1 -0
- package/dist/elements/file-tree.d.ts +1 -0
- package/dist/elements/file-tree.js +1 -0
- package/dist/elements/file-upload.d.ts +1 -0
- package/dist/elements/file-upload.js +1 -0
- package/dist/elements/form.d.ts +1 -0
- package/dist/elements/form.js +1 -0
- package/dist/elements/image.d.ts +1 -0
- package/dist/elements/image.js +1 -0
- package/dist/elements/link-preview.d.ts +1 -0
- package/dist/elements/link-preview.js +1 -0
- package/dist/elements/loader.d.ts +1 -0
- package/dist/elements/loader.js +1 -0
- package/dist/elements/markdown.d.ts +1 -0
- package/dist/elements/markdown.js +1 -0
- package/dist/elements/message-skills.d.ts +1 -0
- package/dist/elements/message-skills.js +1 -0
- package/dist/elements/message.d.ts +1 -0
- package/dist/elements/message.js +1 -0
- package/dist/elements/model-switcher.d.ts +1 -0
- package/dist/elements/model-switcher.js +1 -0
- package/dist/elements/popover.d.ts +1 -0
- package/dist/elements/popover.js +1 -0
- package/dist/elements/prompt-input.d.ts +1 -0
- package/dist/elements/prompt-input.js +1 -0
- package/dist/elements/prompt-suggestions.d.ts +1 -0
- package/dist/elements/prompt-suggestions.js +1 -0
- package/dist/elements/reasoning.d.ts +1 -0
- package/dist/elements/reasoning.js +1 -0
- package/dist/elements/resizable.d.ts +1 -0
- package/dist/elements/resizable.js +1 -0
- package/dist/elements/response-stream.d.ts +1 -0
- package/dist/elements/response-stream.js +14 -0
- package/dist/elements/scroll-button.d.ts +1 -0
- package/dist/elements/scroll-button.js +1 -0
- package/dist/elements/source.d.ts +1 -0
- package/dist/elements/source.js +1 -0
- package/dist/elements/switch.d.ts +1 -0
- package/dist/elements/switch.js +1 -0
- package/dist/elements/tasks.d.ts +1 -0
- package/dist/elements/tasks.js +1 -0
- package/dist/elements/text-shimmer.d.ts +1 -0
- package/dist/elements/text-shimmer.js +1 -0
- package/dist/elements/thinking-bar.d.ts +1 -0
- package/dist/elements/thinking-bar.js +1 -0
- package/dist/elements/toast.d.ts +1 -0
- package/dist/elements/toast.js +1 -0
- package/dist/elements/tool.d.ts +1 -0
- package/dist/elements/tool.js +1 -0
- package/dist/elements/voice-input.d.ts +1 -0
- package/dist/elements/voice-input.js +1 -0
- package/dist/elements.d.ts +768 -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 +124 -2
- package/dist/index.js +15593 -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 +57 -12
- package/dist/llms/llms.txt +3 -3
- package/dist/mcp.es.js +2296 -0
- package/dist/primitives/card-contract.d.ts +119 -0
- package/dist/primitives/card-host.d.ts +12 -0
- package/dist/primitives/card-recovery.d.ts +55 -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/message-feedback.d.ts +35 -0
- package/dist/primitives/pdf-preview.d.ts +50 -0
- package/dist/primitives/toast-store.d.ts +88 -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 +1198 -0
- package/dist/react/runtime.d.ts +15 -0
- package/dist/react.js +275 -0
- package/dist/register-JyTglR6m.js +1 -0
- package/dist/register-impl-C6wlSsts.js +77 -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/schemas/choice.schema.json +5 -0
- package/dist/schemas/tasks.schema.json +5 -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 +9 -0
- package/dist/utils/cn.d.ts +2 -0
- package/dist/vue-BmIZj4XD.js +33 -1
- package/frameworks/react/index.tsx +67 -11
- package/frameworks/react/runtime.tsx +16 -2
- package/llms-full.txt +57 -12
- package/llms.txt +3 -3
- package/package.json +36 -14
- 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 +489 -0
- package/src/agent-tooling/mcp/tools/reference.ts +132 -0
- package/src/agent-tooling/mcp/tools/scaffold.ts +1759 -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/components/chat-thread.tsx +27 -35
- package/src/components/choice-card.tsx +33 -4
- package/src/components/component-meta.json +250 -26
- package/src/components/confirm-card.tsx +15 -1
- package/src/components/dismissed-stub.tsx +80 -0
- package/src/components/form.tsx +21 -3
- package/src/components/message.tsx +151 -10
- package/src/components/response-compare-types.ts +127 -0
- package/src/components/response-compare.tsx +431 -0
- package/src/components/tasks-card.tsx +33 -3
- package/src/components/toast.tsx +398 -0
- package/src/components/use-card-resolution.ts +24 -8
- package/src/elements/autoloader.ts +89 -0
- package/src/elements/chat-types.ts +7 -0
- package/src/elements/chat-workspace.tsx +4 -2
- package/src/elements/chat.tsx +4 -2
- package/src/elements/compare.tsx +88 -0
- package/src/elements/compiled.css +1 -1
- package/src/elements/define.tsx +7 -1
- package/src/elements/element-manifest.json +182 -0
- package/src/elements/element-meta.json +191 -68
- package/src/elements/element-types.d.ts +43 -6
- package/src/elements/framework-usage.json +25 -0
- package/src/elements/message.tsx +27 -45
- package/src/elements/register-impl.ts +58 -0
- package/src/elements/register.ts +26 -51
- package/src/elements/remote.tsx +4 -0
- package/src/elements/styles.css +19 -0
- package/src/elements/toast.tsx +74 -0
- package/src/index.ts +30 -0
- package/src/primitives/card-contract.ts +14 -5
- package/src/primitives/card-recovery.ts +149 -0
- package/src/primitives/card-routing.ts +3 -0
- package/src/primitives/card-schemas/choice.schema.json +5 -0
- package/src/primitives/card-schemas/tasks.schema.json +5 -0
- package/src/primitives/message-feedback.ts +123 -0
- package/src/primitives/toast-store.ts +235 -0
- package/src/ui/tooltip.tsx +8 -2
- package/theme.css +4 -2
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { Tool } from './types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* debug — diagnose common AI/UI (kai-*) integration failures.
|
|
6
|
+
*
|
|
7
|
+
* Given a `symptom` (prose) and/or a `snippet` (code), returns the likely
|
|
8
|
+
* cause + fix for the classic `kai-*` failure modes so a harness can
|
|
9
|
+
* self-correct without a human in the loop.
|
|
10
|
+
*
|
|
11
|
+
* Rule set sourced from:
|
|
12
|
+
* - docs-site/src/content/docs/guides/for-ai-agents.mdx §"What agents most commonly get wrong"
|
|
13
|
+
* - context7.json `rules` array (5 contract rules)
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
interface Rule {
|
|
17
|
+
id: string;
|
|
18
|
+
test: (text: string) => boolean;
|
|
19
|
+
title: string;
|
|
20
|
+
cause: string;
|
|
21
|
+
fix: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const RULES: Rule[] = [
|
|
25
|
+
{
|
|
26
|
+
// Rule 1 — array/object data set as an HTML attribute
|
|
27
|
+
// Source: for-ai-agents.mdx §1; context7.json rule 2
|
|
28
|
+
id: 'array-as-attribute',
|
|
29
|
+
test: (t) =>
|
|
30
|
+
/\b(messages|models|context|suggestions|slashCommands)\s*=\s*["']/.test(t),
|
|
31
|
+
title: 'Array/object prop set as an HTML attribute (silent failure)',
|
|
32
|
+
cause:
|
|
33
|
+
'An HTML attribute is always a string. Passing `messages`, `models`, `context`, ' +
|
|
34
|
+
'`suggestions`, or `slashCommands` as an HTML attribute silently fails — ' +
|
|
35
|
+
'the element receives a stringified value it cannot parse.',
|
|
36
|
+
fix:
|
|
37
|
+
'Set the property in JavaScript, not as an HTML attribute. ' +
|
|
38
|
+
'Only scalar props (`placeholder`, `loading`, `theme`) work as attributes.\n\n' +
|
|
39
|
+
'```js\n' +
|
|
40
|
+
"// ✅ Works — set messages in JavaScript as a property\n" +
|
|
41
|
+
"const chat = document.querySelector('kai-chat');\n" +
|
|
42
|
+
"chat.messages = [{ id: '1', role: 'assistant', content: 'Hello!' }];\n" +
|
|
43
|
+
'```\n\n' +
|
|
44
|
+
'```html\n' +
|
|
45
|
+
'<!-- ❌ Fails — messages cannot be an HTML attribute -->\n' +
|
|
46
|
+
'<kai-chat messages="[...]"></kai-chat>\n' +
|
|
47
|
+
'```',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
// Rule 2 — in-place mutation → no re-render
|
|
51
|
+
// Source: for-ai-agents.mdx §3; context7.json rule 4
|
|
52
|
+
id: 'in-place-mutation',
|
|
53
|
+
test: (t) =>
|
|
54
|
+
/don'?t\s+update|doesn'?t\s+re.?render|no\s+re.?render|\.push\(|\bpush(?:es|ing)?\s+(?:to|into|onto)\b|mutate|in.place/.test(t),
|
|
55
|
+
title: 'In-place mutation does not trigger a re-render',
|
|
56
|
+
cause:
|
|
57
|
+
'Mutating an existing message object or array in place (e.g. `chat.messages.push(…)` ' +
|
|
58
|
+
'or `chat.messages[i].content = …`) does not trigger a re-render. ' +
|
|
59
|
+
'The element only reacts when it detects a new array/object reference.',
|
|
60
|
+
fix:
|
|
61
|
+
'Assign a NEW array (and a new object) on every change — never mutate in place.\n\n' +
|
|
62
|
+
'```js\n' +
|
|
63
|
+
'// ✅ Triggers re-render — new array + new object reference\n' +
|
|
64
|
+
'chat.messages = [\n' +
|
|
65
|
+
' ...chat.messages,\n' +
|
|
66
|
+
" { id: crypto.randomUUID(), role: 'user', content: userText },\n" +
|
|
67
|
+
'];\n\n' +
|
|
68
|
+
'// ✅ During streaming — replace with a new array + new object on every chunk\n' +
|
|
69
|
+
'chat.messages = chat.messages.map((m) =>\n' +
|
|
70
|
+
' m.id === assistantId ? { ...m, content: accumulated } : m\n' +
|
|
71
|
+
');\n\n' +
|
|
72
|
+
'// ❌ Does NOT trigger re-render\n' +
|
|
73
|
+
'chat.messages.push(newMsg);\n' +
|
|
74
|
+
'chat.messages[i].content = accumulated;\n' +
|
|
75
|
+
'```',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
// Rule 3 — listening for events on a parent / wrong element
|
|
79
|
+
// Source: for-ai-agents.mdx §2; context7.json rule 3
|
|
80
|
+
id: 'event-bubbling',
|
|
81
|
+
test: (t) =>
|
|
82
|
+
/event.*not\s+fir|not\s+fir.*event|listen.*document|document.*listen|listen.*parent|parent.*listen|event.*bubbl/i.test(
|
|
83
|
+
t,
|
|
84
|
+
),
|
|
85
|
+
title: 'Listening for events on the wrong element (events are non-bubbling)',
|
|
86
|
+
cause:
|
|
87
|
+
'`kai-*` events are non-bubbling CustomEvents. Adding a listener to `document`, ' +
|
|
88
|
+
'`window`, or a parent container will never fire because the event does not bubble up.',
|
|
89
|
+
fix:
|
|
90
|
+
'Listen directly on the `kai-*` element. ' +
|
|
91
|
+
'The submit event is `kai-submit` with `event.detail.value`.\n\n' +
|
|
92
|
+
'```js\n' +
|
|
93
|
+
"const chat = document.querySelector('kai-chat');\n\n" +
|
|
94
|
+
"// ✅ Listen directly on the element\n" +
|
|
95
|
+
"chat.addEventListener('kai-submit', (e) => {\n" +
|
|
96
|
+
' console.log(e.detail.value); // the text the user typed\n' +
|
|
97
|
+
'});\n\n' +
|
|
98
|
+
"// ❌ Never fires — kai-submit does not bubble\n" +
|
|
99
|
+
"document.addEventListener('kai-submit', handler);\n" +
|
|
100
|
+
'```\n\n' +
|
|
101
|
+
'Common events: `kai-submit`, `kai-feedback`, `kai-model-change`, `kai-new-chat`, `kai-select`.',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
// Rule 4 — wrong element prefix kitn-
|
|
105
|
+
// Source: context7.json rule 1
|
|
106
|
+
id: 'wrong-prefix',
|
|
107
|
+
test: (t) => /\bkitn-/.test(t),
|
|
108
|
+
title: 'Wrong element prefix `kitn-` (should be `kai-`)',
|
|
109
|
+
cause:
|
|
110
|
+
'The custom element prefix is `kai-` (e.g. `<kai-chat>`, `<kai-artifact>`). ' +
|
|
111
|
+
'`kitn-chat` is only a bundle filename — it is not a registered element name. ' +
|
|
112
|
+
'Using `<kitn-chat>` results in an unknown element that renders nothing.',
|
|
113
|
+
fix:
|
|
114
|
+
'Replace the `kitn-` prefix with `kai-` everywhere.\n\n' +
|
|
115
|
+
'```html\n' +
|
|
116
|
+
'<!-- ✅ Correct element prefix -->\n' +
|
|
117
|
+
'<kai-chat></kai-chat>\n' +
|
|
118
|
+
'<kai-artifact></kai-artifact>\n\n' +
|
|
119
|
+
'<!-- ❌ Wrong — kitn-chat is a bundle filename, not an element -->\n' +
|
|
120
|
+
'<kitn-chat></kitn-chat>\n' +
|
|
121
|
+
'```',
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
// Rule 6 — custom elements not registered / renders nothing (React #1 failure)
|
|
125
|
+
// Source: field-test reports; for-ai-agents.mdx §"Import order matters"
|
|
126
|
+
id: 'elements-not-registered',
|
|
127
|
+
test: (t) => {
|
|
128
|
+
// Core render-nothing / unregistered-element signals
|
|
129
|
+
if (
|
|
130
|
+
/renders?\s+nothing|nothing\s+renders?|not\s+registered|unregistered|not\s+upgraded|unknown\s+element|customElements\.get|undefined\s+element|no\s+shadow\s+root/.test(t)
|
|
131
|
+
)
|
|
132
|
+
return true;
|
|
133
|
+
// "empty" / "blank" / "doesn't render" / "won't render" only fire when
|
|
134
|
+
// a render/element/component context is also present to avoid false positives
|
|
135
|
+
if (
|
|
136
|
+
/\b(empty|blank)\b/.test(t) &&
|
|
137
|
+
/render|element|component|kai-|<[a-z]+-|shadow/.test(t)
|
|
138
|
+
)
|
|
139
|
+
return true;
|
|
140
|
+
if (
|
|
141
|
+
/doesn'?t\s+render|won'?t\s+render/.test(t) &&
|
|
142
|
+
/kai-|element|component|custom.?element/.test(t)
|
|
143
|
+
)
|
|
144
|
+
return true;
|
|
145
|
+
return false;
|
|
146
|
+
},
|
|
147
|
+
title: 'Custom elements not registered — renders nothing / empty box',
|
|
148
|
+
cause:
|
|
149
|
+
'The `@kitn.ai/ui/react` wrappers (and bare `<kai-*>` tags) do NOT register the ' +
|
|
150
|
+
'custom elements by themselves. Without the element-registration side-effect import, ' +
|
|
151
|
+
'`<kai-chat>` / `<Chat>` is an un-upgraded unknown element — an empty box. ' +
|
|
152
|
+
'`customElements.get(\'kai-chat\') === undefined`.',
|
|
153
|
+
fix:
|
|
154
|
+
'Import the elements bundle for its side effect BEFORE your first render — ' +
|
|
155
|
+
'it must run before the component mounts.\n\n' +
|
|
156
|
+
'```tsx\n' +
|
|
157
|
+
"import '@kitn.ai/ui/elements' // registers <kai-*> — REQUIRED, must come first\n" +
|
|
158
|
+
"import { Chat } from '@kitn.ai/ui/react'\n" +
|
|
159
|
+
"import '@kitn.ai/ui/theme.css'\n" +
|
|
160
|
+
'```\n\n' +
|
|
161
|
+
'In plain HTML: `import \'@kitn.ai/ui/elements\'` in your module script. ' +
|
|
162
|
+
'The import is a side effect — keep it even if your linter flags it as "unused".',
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
// Rule 7 — tsc errors inside node_modules/@kitn.ai/ui/src (SolidJS source pulled in)
|
|
166
|
+
// Source: field-test reports; packaging gap (tracked upstream)
|
|
167
|
+
id: 'tsc-source-pull',
|
|
168
|
+
test: (t) =>
|
|
169
|
+
/node_modules\/@kitn\.ai\/ui/.test(t) &&
|
|
170
|
+
/tsc|TS2786|cannot\s+be\s+used\s+as\s+a\s+jsx\s+component|Show\b|Portal\b|Dynamic\b|error\s+TS|type\s+error/.test(
|
|
171
|
+
t,
|
|
172
|
+
),
|
|
173
|
+
title: 'tsc errors inside node_modules/@kitn.ai/ui/src (SolidJS source compiled under React)',
|
|
174
|
+
cause:
|
|
175
|
+
'The package currently ships TypeScript/TSX source, and a type entry value-re-exports ' +
|
|
176
|
+
'from it, so the consumer\'s `tsc` resolves and compiles the library\'s SolidJS internals ' +
|
|
177
|
+
'(`src/ui/*.tsx`) under the app\'s React JSX config — `Show`/`Portal`/`Dynamic` aren\'t ' +
|
|
178
|
+
'React components, causing TS2786 / "cannot be used as a JSX component" errors. ' +
|
|
179
|
+
'`vite`/esbuild build fine (they strip types); only `tsc` breaks. ' +
|
|
180
|
+
'`skipLibCheck` does not help (these are `.tsx` source, not `.d.ts`).',
|
|
181
|
+
fix:
|
|
182
|
+
'Redirect the type resolution for that subpath in your tsconfig ' +
|
|
183
|
+
'(Vite ignores tsconfig `paths`, so runtime is unaffected):\n\n' +
|
|
184
|
+
'```jsonc\n' +
|
|
185
|
+
'// tsconfig (app)\n' +
|
|
186
|
+
'"baseUrl": ".",\n' +
|
|
187
|
+
'"paths": { "@kitn.ai/ui/elements": ["./src/stubs/kitn-elements.d.ts"] }\n' +
|
|
188
|
+
'```\n\n' +
|
|
189
|
+
'```ts\n' +
|
|
190
|
+
'// src/stubs/kitn-elements.d.ts\n' +
|
|
191
|
+
'export {}\n' +
|
|
192
|
+
'```\n\n' +
|
|
193
|
+
'(This is a known packaging gap being tracked upstream.)',
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
// Rule 8 — fetch('/api/chat') 404 in a Vite SPA (no server-side routes)
|
|
197
|
+
// Source: field-test reports; common scaffold confusion
|
|
198
|
+
id: 'vite-api-404',
|
|
199
|
+
test: (t) => {
|
|
200
|
+
// /api/chat 404
|
|
201
|
+
if (/\/api\/chat/.test(t) && /\b404\b|not\s+found/i.test(t)) return true;
|
|
202
|
+
// Vite + missing API route / route handler / POST
|
|
203
|
+
if (/\bvite\b/.test(t) && /api\s+route|route\s+handler|\bPOST\b.*not\s+work/.test(t)) return true;
|
|
204
|
+
// Next.js route handler used in a Vite app
|
|
205
|
+
if (/next\.?js.*route|route.*next\.?js/.test(t) && /\bvite\b/.test(t)) return true;
|
|
206
|
+
return false;
|
|
207
|
+
},
|
|
208
|
+
title: 'fetch(\'/api/chat\') 404 — Vite SPA has no server-side API routes',
|
|
209
|
+
cause:
|
|
210
|
+
'A plain Vite/CRA React SPA has no server — there are no `/api` routes. ' +
|
|
211
|
+
'A scaffolded Next.js route handler (`export async function POST`) does not run there, ' +
|
|
212
|
+
'so `fetch(\'/api/chat\')` 404s.',
|
|
213
|
+
fix:
|
|
214
|
+
'Either run the backend somewhere real, or skip it entirely for local dev:\n\n' +
|
|
215
|
+
'```ts\n' +
|
|
216
|
+
'// Option A — use Next.js where route handlers are supported\n' +
|
|
217
|
+
"// app/api/chat/route.ts: export async function POST(req) { ... }\n\n" +
|
|
218
|
+
'// Option B — add a Vite dev-server middleware/proxy\n' +
|
|
219
|
+
"// vite.config.ts: server: { proxy: { '/api': 'http://localhost:3001' } }\n\n" +
|
|
220
|
+
'// Option C — run a separate Express/Hono server\n' +
|
|
221
|
+
"// framework: 'express' in your harness config\n\n" +
|
|
222
|
+
'// Option D — zero-config local dev with mock integration (no backend needed)\n' +
|
|
223
|
+
"// Use `integration: 'mock'` in the scaffold tool\n" +
|
|
224
|
+
'```',
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
// Rule 9 — reduce bundle size / footprint / "how much does @kitn.ai/ui add"
|
|
228
|
+
// Source: dist/elements/<file>.js per-element exports; dist/autoloader.js
|
|
229
|
+
id: 'bundle-footprint',
|
|
230
|
+
test: (t) =>
|
|
231
|
+
/bundle\s*size|footprint|tree.?shak|how\s+much.*does.*@kitn|reduce.*import|import.*only.*element|per.?element\s+import|autoload|cdn.*no.?build|no.?build.*cdn/i.test(
|
|
232
|
+
t,
|
|
233
|
+
),
|
|
234
|
+
title: 'Reducing bundle footprint — three load modes',
|
|
235
|
+
cause:
|
|
236
|
+
'The default `import \'@kitn.ai/ui/elements\'` registers every `kai-*` element. ' +
|
|
237
|
+
'If your page uses only one or two elements, that pulls in the full ~119 KB gz bundle. ' +
|
|
238
|
+
'Two opt-in modes let you load only what you need.',
|
|
239
|
+
fix:
|
|
240
|
+
'**Mode 1 — register-all (default, SSR-safe):**\n' +
|
|
241
|
+
'Best for multi-element apps or any SSR/meta-framework. ' +
|
|
242
|
+
'Load once and every `kai-*` element is available.\n\n' +
|
|
243
|
+
'```js\n' +
|
|
244
|
+
"import '@kitn.ai/ui/elements'; // ~119 KB gz — registers everything\n" +
|
|
245
|
+
'```\n\n' +
|
|
246
|
+
'**Mode 2 — per-element import (tree-shaking, bundler apps):**\n' +
|
|
247
|
+
'Use `import \'@kitn.ai/ui/elements/<file>\'` to register only one element. ' +
|
|
248
|
+
'A bundler (Vite, webpack, Rollup) will tree-shake to just its chunks (~73 KB gz for `kai-chat` alone). ' +
|
|
249
|
+
'Client-only — do not use in SSR entry points.\n\n' +
|
|
250
|
+
'```js\n' +
|
|
251
|
+
"// Registers only <kai-chat> (~73 KB gz vs ~119 KB gz register-all)\n" +
|
|
252
|
+
"import '@kitn.ai/ui/elements/chat';\n\n" +
|
|
253
|
+
"// Other examples:\n" +
|
|
254
|
+
"import '@kitn.ai/ui/elements/code-block'; // <kai-code-block>\n" +
|
|
255
|
+
"import '@kitn.ai/ui/elements/confirm-card'; // <kai-confirm>\n" +
|
|
256
|
+
'```\n\n' +
|
|
257
|
+
'The file name is the element\'s source basename from `element-manifest.json` ' +
|
|
258
|
+
'(e.g. `kai-chat` → `chat`, `kai-confirm` → `confirm-card`).\n\n' +
|
|
259
|
+
'**Mode 3 — autoloader (no-build / CDN pages only):**\n' +
|
|
260
|
+
'Watches the DOM and dynamically imports each `kai-*` element\'s module on demand. ' +
|
|
261
|
+
'A page that uses only `<kai-chat>` never downloads the other elements. ' +
|
|
262
|
+
'It is a CDN / static-file tool — load it from a `<script type="module">` tag. ' +
|
|
263
|
+
'It is NOT importable through a bundler: Vite/webpack relocate it and the on-demand imports 404. ' +
|
|
264
|
+
'Client-only.\n\n' +
|
|
265
|
+
'```html\n' +
|
|
266
|
+
'<script type="module" src="https://cdn.jsdelivr.net/npm/@kitn.ai/ui@<version>/dist/elements/autoloader.js"></script>\n' +
|
|
267
|
+
'```\n\n' +
|
|
268
|
+
'In a BUNDLED app (Vite/webpack/Next) use Mode 1 or Mode 2 instead — not the autoloader.\n\n' +
|
|
269
|
+
'**SSR note:** use Mode 1 (register-all) in SSR apps — ' +
|
|
270
|
+
'per-element imports and the autoloader are client-only (they call DOM APIs at module eval). ' +
|
|
271
|
+
'Modes 1 & 2 are side-effect imports; keep them even if your linter flags them as "unused".',
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
// Rule 5 — SSR / server component / document is not defined
|
|
275
|
+
// Source: for-ai-agents.mdx (client-only import); context7.json rule 2 (property rule requires DOM)
|
|
276
|
+
id: 'ssr-server-component',
|
|
277
|
+
test: (t) => {
|
|
278
|
+
// Core SSR signals — always trigger
|
|
279
|
+
if (/\bssr\b|server\s+component|document\s+is\s+not\s+defined|window\s+is\s+not\s+defined|next\.?js.*server|server.*next\.?js/.test(t)) return true;
|
|
280
|
+
// "hydration" only triggers when a web-component / kai context is also present
|
|
281
|
+
if (/hydration/.test(t) && /kai|web.?component|custom.?element|<[a-z]+-/.test(t)) return true;
|
|
282
|
+
return false;
|
|
283
|
+
},
|
|
284
|
+
title: 'SSR / server-side rendering — element requires the browser DOM',
|
|
285
|
+
cause:
|
|
286
|
+
'`kai-*` elements are client-side web components. They require `document` and ' +
|
|
287
|
+
'`customElements` to register and render. Importing them in a server component ' +
|
|
288
|
+
'(Next.js App Router server component, Nuxt SSR, etc.) throws ' +
|
|
289
|
+
'"document is not defined" or silently produces no output.',
|
|
290
|
+
fix:
|
|
291
|
+
'Register the element on the client only. ' +
|
|
292
|
+
'Use your framework\'s "client-only" / island / dynamic-import pattern.\n\n' +
|
|
293
|
+
'```js\n' +
|
|
294
|
+
"// ✅ Plain HTML / vanilla — import in a <script type=\"module\">\n" +
|
|
295
|
+
"import '@kitn.ai/ui/elements';\n\n" +
|
|
296
|
+
'// ✅ Next.js App Router — mark the component with "use client"\n' +
|
|
297
|
+
"'use client';\n" +
|
|
298
|
+
"import '@kitn.ai/ui/elements';\n\n" +
|
|
299
|
+
'// ✅ Next.js — dynamic import with ssr: false\n' +
|
|
300
|
+
"import dynamic from 'next/dynamic';\n" +
|
|
301
|
+
"const KaiChat = dynamic(() => import('@kitn.ai/ui/elements').then(() => 'kai-chat'), { ssr: false });\n\n" +
|
|
302
|
+
'// ✅ React wrapper (already client-safe)\n' +
|
|
303
|
+
"import { Chat } from '@kitn.ai/ui/react';\n" +
|
|
304
|
+
'```',
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
// Rule 10 — toast() is the imperative API; there is no <kai-toast> to place
|
|
308
|
+
// Source: src/primitives/toast-store.ts (the `toast` fn + auto-mounted region)
|
|
309
|
+
id: 'toast-imperative',
|
|
310
|
+
test: (t) => {
|
|
311
|
+
// Placing a toast element by hand (the region auto-mounts — you never write it).
|
|
312
|
+
if (/<kai-toast(-region)?\b/.test(t)) return true;
|
|
313
|
+
// Asking how to show / trigger a toast or notification with kai context.
|
|
314
|
+
if (
|
|
315
|
+
/\btoast(s)?\b|notification|snackbar/i.test(t) &&
|
|
316
|
+
/how.*(show|raise|trigger|fire|display)|show.*toast|raise.*toast|trigger.*toast|toast.*(not|isn'?t|won'?t).*(show|appear|render)|where.*toast|add.*toast|kai-|@kitn/i.test(t)
|
|
317
|
+
)
|
|
318
|
+
return true;
|
|
319
|
+
return false;
|
|
320
|
+
},
|
|
321
|
+
title: 'Toast is an imperative call — `toast(\'…\')`, not a `<kai-toast>` you place',
|
|
322
|
+
cause:
|
|
323
|
+
'Toasts are raised IMPERATIVELY by calling `toast(message)` — there is no ' +
|
|
324
|
+
'`<kai-toast>` element you add to your markup. The first call lazily mounts ONE ' +
|
|
325
|
+
'`<kai-toast-region>` on `document.body` (a real, kit-styled, viewport-positioned ' +
|
|
326
|
+
'element) and every later toast feeds that same region. Trying to place a toast ' +
|
|
327
|
+
'element by hand, or looking for a `messages`/`toasts` prop to push into, is the ' +
|
|
328
|
+
'wrong model.',
|
|
329
|
+
fix:
|
|
330
|
+
'Import `toast` and call it. It is exported from BOTH the root `@kitn.ai/ui` and ' +
|
|
331
|
+
'the `@kitn.ai/ui/elements` bundle, so the web-components-only consumer gets it too. ' +
|
|
332
|
+
'It is SSR-safe (no DOM is touched until the first call on the client).\n\n' +
|
|
333
|
+
'```js\n' +
|
|
334
|
+
"import { toast } from '@kitn.ai/ui/elements'; // or '@kitn.ai/ui'\n\n" +
|
|
335
|
+
"// ✅ Fire-and-forget\n" +
|
|
336
|
+
"toast('Copied to clipboard');\n" +
|
|
337
|
+
"toast.success('Saved');\n\n" +
|
|
338
|
+
"// ✅ With an Undo action + an imperative handle\n" +
|
|
339
|
+
"const t = toast('Item deleted', {\n" +
|
|
340
|
+
" action: { label: 'Undo', onAction: () => restore() },\n" +
|
|
341
|
+
'});\n' +
|
|
342
|
+
"t.update({ message: 'Restored', variant: 'success' });\n" +
|
|
343
|
+
't.dismiss();\n' +
|
|
344
|
+
'```\n\n' +
|
|
345
|
+
'The auto-mounted `<kai-toast-region>` carries its own shadow root + kit styles — ' +
|
|
346
|
+
'do NOT add a `<kai-toast-region>` tag yourself unless you deliberately want a ' +
|
|
347
|
+
'second, declaratively-controlled region.',
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
// Rule 11 — dismissed cards are DEFERRED (reopenable stub), not deleted
|
|
351
|
+
// Source: src/primitives/card-recovery.ts (dismissRecovery) + the dismissed stub
|
|
352
|
+
id: 'card-dismiss-deferred',
|
|
353
|
+
test: (t) => {
|
|
354
|
+
const cardCtx = /\bcard(s)?\b|envelope|kai-card|kai-cards|kai-confirm|kai-choice|kai-tasks|kai-form|generative.?ui|resolution|dismissRecovery/i;
|
|
355
|
+
if (!cardCtx.test(t)) return false;
|
|
356
|
+
// dismiss / reopen / undo / disappear / filter-out signals in a card context.
|
|
357
|
+
return /dismiss|reopen|re-?open|\bundo\b|disappear|remove.*card|card.*(gone|remove|delete|vanish)|filter.*out|stub/i.test(t);
|
|
358
|
+
},
|
|
359
|
+
title: 'Dismissed cards are DEFERRED (a reopenable stub), not deleted',
|
|
360
|
+
cause:
|
|
361
|
+
'Dismissing a generative-UI card does NOT delete its envelope from history. The ' +
|
|
362
|
+
'card stamps a `{ kind: \'dismissed\' }` resolution onto its envelope and collapses ' +
|
|
363
|
+
'to a small reopenable stub ("Proposed: <title> — dismissed · Reopen"). If you ' +
|
|
364
|
+
'filter `dismissed` envelopes out of your cards array, the stub vanishes and the ' +
|
|
365
|
+
'user can never reopen it — and you lose the audit trail of what was proposed.',
|
|
366
|
+
fix:
|
|
367
|
+
'Keep dismissed envelopes in the array. Wire dismiss/reopen with `dismissRecovery()` ' +
|
|
368
|
+
'(from `@kitn.ai/ui`), which builds the `onDismiss`/`onReopen` half of a `CardPolicy` ' +
|
|
369
|
+
'over your store and can show a "Dismissed · Undo" toast via an injected adapter.\n\n' +
|
|
370
|
+
'```ts\n' +
|
|
371
|
+
"import { dismissRecovery } from '@kitn.ai/ui';\n" +
|
|
372
|
+
"import { toast } from '@kitn.ai/ui/elements';\n\n" +
|
|
373
|
+
'// Adapter: map dismissRecovery\'s toast shape onto the imperative toast().\n' +
|
|
374
|
+
'const toastAdapter = {\n' +
|
|
375
|
+
' show: ({ message, action, durationMs }) => {\n' +
|
|
376
|
+
" const handle = toast(message, {\n" +
|
|
377
|
+
' duration: durationMs,\n' +
|
|
378
|
+
' action: action && { label: action.label, onAction: action.onClick },\n' +
|
|
379
|
+
' });\n' +
|
|
380
|
+
' return { dismiss: handle.dismiss };\n' +
|
|
381
|
+
' },\n' +
|
|
382
|
+
'};\n\n' +
|
|
383
|
+
'const { onDismiss, onReopen } = dismissRecovery({\n' +
|
|
384
|
+
' get: () => cards, // your current envelopes\n' +
|
|
385
|
+
' set: (next) => setCards(next), // NEW array reference (never mutate in place)\n' +
|
|
386
|
+
' toast: toastAdapter,\n' +
|
|
387
|
+
'});\n' +
|
|
388
|
+
'// Pass these on the CardPolicy you hand to <kai-cards> / <kai-remote>.\n' +
|
|
389
|
+
'```\n\n' +
|
|
390
|
+
'`onDismiss` writes `dismissed` immutably (Undo restores the prior resolution); ' +
|
|
391
|
+
'`onReopen` clears it back to live (or stamps `expired` when the host says the card ' +
|
|
392
|
+
'is no longer reopenable). Never mutate the array in place — re-render needs a new ref.',
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
// Rule 12 — kai-compare contract: two candidates, JS data prop, stream both, terminal pick
|
|
396
|
+
// Source: src/elements/compare.tsx + src/components/response-compare-types.ts
|
|
397
|
+
id: 'compare-contract',
|
|
398
|
+
test: (t) => {
|
|
399
|
+
if (/<kai-compare\b|kai-compare-select|ResponseCompareData|response.?compare/i.test(t)) return true;
|
|
400
|
+
// "compare two responses / candidates / A vs B" with a kai/UI context.
|
|
401
|
+
if (
|
|
402
|
+
/compar(e|ing|ison)|side.by.side|a\/b|two\s+(responses|candidates|answers|completions)|dual.?response/i.test(t) &&
|
|
403
|
+
/kai-|@kitn|candidate|prefer(ence)?|chosen|reject/i.test(t)
|
|
404
|
+
)
|
|
405
|
+
return true;
|
|
406
|
+
return false;
|
|
407
|
+
},
|
|
408
|
+
title: '`kai-compare` — two candidates, `data` as a JS property, terminal pick',
|
|
409
|
+
cause:
|
|
410
|
+
'`<kai-compare>` shows EXACTLY two assistant candidates for one prompt and lets the ' +
|
|
411
|
+
'user pick the better one. The `data` value is an array/object, so it must be set as ' +
|
|
412
|
+
'a JS PROPERTY (never an HTML attribute). Both candidates can stream — but, like ' +
|
|
413
|
+
'`kai-chat`, that needs a NEW `data` reference per chunk (mutating in place will not ' +
|
|
414
|
+
're-render). The pick is a COMMIT (not a Submit): it fires once and the card collapses.',
|
|
415
|
+
fix:
|
|
416
|
+
'Set `data` in JS with two candidates, stream by reassigning a fresh `data` object ' +
|
|
417
|
+
'per chunk, and listen for `kai-compare-select` directly on the element.\n\n' +
|
|
418
|
+
'```ts\n' +
|
|
419
|
+
"import { toast } from '@kitn.ai/ui/elements';\n" +
|
|
420
|
+
"import type { ResponseCompareData, CompareSelection } from '@kitn.ai/ui';\n\n" +
|
|
421
|
+
"const el = document.querySelector('kai-compare')!;\n" +
|
|
422
|
+
'// data is a JS PROPERTY — exactly two candidates, each with a unique id.\n' +
|
|
423
|
+
'el.data = {\n' +
|
|
424
|
+
" prompt: 'Summarise the report',\n" +
|
|
425
|
+
' candidates: [\n' +
|
|
426
|
+
" { id: 'a', content: '', streaming: true },\n" +
|
|
427
|
+
" { id: 'b', content: '', streaming: true },\n" +
|
|
428
|
+
' ],\n' +
|
|
429
|
+
'} satisfies ResponseCompareData;\n\n' +
|
|
430
|
+
'// Stream BOTH columns: replace data with a NEW object per chunk.\n' +
|
|
431
|
+
"el.data = { ...el.data, candidates: [{ ...a, content: aText }, { ...b, content: bText }] };\n" +
|
|
432
|
+
'// Clear `streaming` on a candidate when it settles — the pick stays disabled\n' +
|
|
433
|
+
'// until BOTH have settled, then `kai-ready` fires.\n\n' +
|
|
434
|
+
"// Picking is terminal: emits { chosenId, rejectedIds, at } and collapses.\n" +
|
|
435
|
+
"el.addEventListener('kai-compare-select', (e) => {\n" +
|
|
436
|
+
' const { chosenId, rejectedIds } = (e as CustomEvent<CompareSelection>).detail;\n' +
|
|
437
|
+
' recordPreference({ prompt, chosen: chosenId, rejected: rejectedIds });\n' +
|
|
438
|
+
'});\n' +
|
|
439
|
+
'```\n\n' +
|
|
440
|
+
'A malformed definition (not two candidates, missing/duplicate ids) fires `kai-error` ' +
|
|
441
|
+
'instead. The event is non-bubbling — listen on the element, not on `document`.',
|
|
442
|
+
},
|
|
443
|
+
];
|
|
444
|
+
|
|
445
|
+
function buildText(matched: Rule[]): string {
|
|
446
|
+
if (matched.length === 0) {
|
|
447
|
+
return (
|
|
448
|
+
'No known failure pattern matched. Suggested next steps:\n\n' +
|
|
449
|
+
'1. Use the `component_reference` tool to look up the real API for the element ' +
|
|
450
|
+
'(prop names, event names, attribute vs. property distinction).\n' +
|
|
451
|
+
'2. Check the **Streaming recipe** in `llms-full.txt` ' +
|
|
452
|
+
'(`node_modules/@kitn.ai/ui/llms-full.txt` or https://ui.kitn.ai/llms-full.txt) ' +
|
|
453
|
+
'for correct streaming wiring.\n' +
|
|
454
|
+
'3. Paste `https://ui.kitn.ai/llms.txt` into your prompt for a compact orientation.'
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
const sections = matched.map((rule, i) => {
|
|
459
|
+
const n = i + 1;
|
|
460
|
+
return `## ${n}. ${rule.title}\n\n**Cause:** ${rule.cause}\n\n**Fix:** ${rule.fix}`;
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
const header =
|
|
464
|
+
matched.length === 1
|
|
465
|
+
? '1 likely cause found:\n\n'
|
|
466
|
+
: `${matched.length} likely causes found:\n\n`;
|
|
467
|
+
|
|
468
|
+
return header + sections.join('\n\n---\n\n');
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
export const debug: Tool = {
|
|
472
|
+
name: 'debug',
|
|
473
|
+
description:
|
|
474
|
+
'Diagnose common AI/UI (kai-*) integration issues. ' +
|
|
475
|
+
'Provide a `symptom` (prose description) and/or a `snippet` (code) ' +
|
|
476
|
+
'and receive the likely cause + fix for classic kai-* failure modes.',
|
|
477
|
+
inputSchema: z.object({
|
|
478
|
+
symptom: z.string().optional(),
|
|
479
|
+
snippet: z.string().optional(),
|
|
480
|
+
}),
|
|
481
|
+
handler: async (args) => {
|
|
482
|
+
const combined = `${(args.symptom as string | undefined) ?? ''} ${(args.snippet as string | undefined) ?? ''}`;
|
|
483
|
+
const matched = RULES.filter((rule) => rule.test(combined));
|
|
484
|
+
|
|
485
|
+
return {
|
|
486
|
+
content: [{ type: 'text', text: buildText(matched) }],
|
|
487
|
+
};
|
|
488
|
+
},
|
|
489
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { Tool } from './types';
|
|
3
|
+
import { getElement, listElements } from '../manifest';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* component_reference — look up AI/UI (kai-*) web components, their props,
|
|
7
|
+
* events, attributes, and CSS custom properties from the live Custom Elements
|
|
8
|
+
* Manifest (dist/custom-elements.json).
|
|
9
|
+
*
|
|
10
|
+
* Backed by manifest.ts which resolves the CEM in both the bundled bin
|
|
11
|
+
* (dist/mcp.es.js sibling) and the Vitest source context (walks up to find
|
|
12
|
+
* dist/custom-elements.json in the repo root).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** Types that warrant the JS-property contract note. */
|
|
16
|
+
const JS_ONLY_TYPE_PATTERNS = /\[\]|\{|Record</;
|
|
17
|
+
|
|
18
|
+
function isJsOnlyType(typeText: string | undefined): boolean {
|
|
19
|
+
return typeText ? JS_ONLY_TYPE_PATTERNS.test(typeText) : false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function formatReference(tag: string): string {
|
|
23
|
+
const el = getElement(tag);
|
|
24
|
+
|
|
25
|
+
if (!el) {
|
|
26
|
+
const all = listElements();
|
|
27
|
+
const sample = all.slice(0, 5).join(', ');
|
|
28
|
+
return (
|
|
29
|
+
`Unknown element: ${tag}\n\n` +
|
|
30
|
+
`Valid tags include: ${sample} (and ${Math.max(0, all.length - 5)} more).\n` +
|
|
31
|
+
`Call component_reference with no name (or name: "list") to list all ${all.length} elements.`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const lines: string[] = [];
|
|
36
|
+
|
|
37
|
+
// ── Header ─────────────────────────────────────────────────────────────────
|
|
38
|
+
lines.push(`## <${tag}>`);
|
|
39
|
+
if (el.description) {
|
|
40
|
+
lines.push('', el.description.trim());
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// ── Contract note ──────────────────────────────────────────────────────────
|
|
44
|
+
lines.push(
|
|
45
|
+
'',
|
|
46
|
+
'### AI/UI contract',
|
|
47
|
+
'`kai-*` elements accept **array and object data as JavaScript properties** ' +
|
|
48
|
+
'(set in JavaScript via `el.property = value`, not as HTML attributes). ' +
|
|
49
|
+
'Events are native CustomEvents — listen with `el.addEventListener("event-name", handler)` ' +
|
|
50
|
+
'and read `event.detail` for the payload.',
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
// ── Public JS properties ───────────────────────────────────────────────────
|
|
54
|
+
const publicFields = (el.members ?? []).filter(
|
|
55
|
+
(m) => m.kind === 'field' && m.privacy === 'public',
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
if (publicFields.length > 0) {
|
|
59
|
+
lines.push('', '### Props (JavaScript properties)');
|
|
60
|
+
for (const field of publicFields) {
|
|
61
|
+
const type = field.type?.text ?? 'unknown';
|
|
62
|
+
const jsOnly = isJsOnlyType(type);
|
|
63
|
+
const desc = field.description?.trim() ?? '';
|
|
64
|
+
const note = jsOnly ? ' ⚑ set as a JS property, not an HTML attribute' : '';
|
|
65
|
+
lines.push(`- **${field.name}** \`${type}\`${note}`);
|
|
66
|
+
if (desc) {
|
|
67
|
+
lines.push(` ${desc}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ── HTML attributes ────────────────────────────────────────────────────────
|
|
73
|
+
const attrs = el.attributes ?? [];
|
|
74
|
+
if (attrs.length > 0) {
|
|
75
|
+
lines.push('', '### Attributes (HTML-safe)');
|
|
76
|
+
for (const attr of attrs) {
|
|
77
|
+
const type = attr.type?.text ?? 'unknown';
|
|
78
|
+
const desc = attr.description?.trim() ?? '';
|
|
79
|
+
lines.push(`- **${attr.name}** \`${type}\``);
|
|
80
|
+
if (desc) {
|
|
81
|
+
lines.push(` ${desc}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ── Events ────────────────────────────────────────────────────────────────
|
|
87
|
+
const events = el.events ?? [];
|
|
88
|
+
if (events.length > 0) {
|
|
89
|
+
lines.push('', '### Events (CustomEvent, listen via addEventListener)');
|
|
90
|
+
for (const ev of events) {
|
|
91
|
+
const desc = ev.description?.trim() ?? '';
|
|
92
|
+
lines.push(`- **${ev.name}** — ${desc}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// ── CSS custom properties ─────────────────────────────────────────────────
|
|
97
|
+
const cssProps = el.cssProperties ?? [];
|
|
98
|
+
if (cssProps.length > 0) {
|
|
99
|
+
lines.push('', '### CSS custom properties');
|
|
100
|
+
for (const prop of cssProps) {
|
|
101
|
+
const desc = prop.description?.trim() ?? '';
|
|
102
|
+
const def = prop.default ? ` (default: ${prop.default})` : '';
|
|
103
|
+
lines.push(`- **${prop.name}**${def}${desc ? ` — ${desc}` : ''}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return lines.join('\n');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const reference: Tool = {
|
|
111
|
+
name: 'component_reference',
|
|
112
|
+
description:
|
|
113
|
+
'Look up AI/UI (kai-*) web components: their tags, props, events, and usage examples.',
|
|
114
|
+
inputSchema: z.object({ name: z.string().optional() }),
|
|
115
|
+
handler: async (args: Record<string, unknown>) => {
|
|
116
|
+
const name = typeof args.name === 'string' ? args.name.trim() : undefined;
|
|
117
|
+
|
|
118
|
+
let text: string;
|
|
119
|
+
|
|
120
|
+
if (!name || name === 'list') {
|
|
121
|
+
const tags = listElements();
|
|
122
|
+
text =
|
|
123
|
+
`AI/UI elements (${tags.length} total):\n\n` +
|
|
124
|
+
tags.map((t) => ` ${t}`).join('\n') +
|
|
125
|
+
'\n\nCall component_reference with a specific name (e.g. { name: "kai-chat" }) for full API details.';
|
|
126
|
+
} else {
|
|
127
|
+
text = formatReference(name);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return { content: [{ type: 'text' as const, text }] };
|
|
131
|
+
},
|
|
132
|
+
};
|