@kitn.ai/ui 0.16.0 → 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 +28 -13
- package/dist/components/chat-thread.d.ts +2 -4
- package/dist/components/choice-card.d.ts +1 -0
- package/dist/components/dismissed-stub.d.ts +22 -0
- package/dist/components/message.d.ts +59 -2
- package/dist/components/response-compare-types.d.ts +66 -0
- package/dist/components/response-compare.d.ts +51 -0
- package/dist/components/tasks-card.d.ts +1 -0
- package/dist/components/toast.d.ts +48 -0
- package/dist/components/use-card-resolution.d.ts +10 -6
- package/dist/custom-elements.json +260 -11
- package/dist/elements/artifact.js +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.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 +0 -12
- package/dist/elements/chain-of-thought.js +1 -0
- package/dist/elements/chat-scope-picker.js +1 -0
- package/dist/elements/chat-workspace.js +1 -0
- package/dist/elements/chat.js +1 -0
- package/dist/elements/checkpoint.js +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.js +1 -0
- package/dist/elements/compare.js +1 -0
- package/dist/elements/confirm-card.js +1 -0
- package/dist/elements/context-meter.js +1 -0
- package/dist/elements/conversation-list.d.ts +1 -11
- package/dist/elements/conversation-list.js +1 -0
- package/dist/elements/embed.js +1 -0
- package/dist/elements/empty.js +1 -0
- package/dist/elements/feedback-bar.js +1 -0
- package/dist/elements/file-tree.js +1 -0
- package/dist/elements/file-upload.js +1 -0
- package/dist/elements/form.js +1 -0
- package/dist/elements/image.js +1 -0
- package/dist/elements/link-preview.js +1 -0
- package/dist/elements/loader.js +1 -0
- package/dist/elements/markdown.js +1 -0
- package/dist/elements/message-skills.d.ts +0 -16
- package/dist/elements/message-skills.js +1 -0
- package/dist/elements/message.js +1 -0
- package/dist/elements/model-switcher.d.ts +1 -11
- package/dist/elements/model-switcher.js +1 -0
- package/dist/elements/popover.js +1 -0
- package/dist/elements/prompt-input.d.ts +1 -9
- package/dist/elements/prompt-input.js +1 -0
- package/dist/elements/prompt-suggestions.d.ts +0 -6
- package/dist/elements/prompt-suggestions.js +1 -0
- package/dist/elements/reasoning.js +1 -0
- package/dist/elements/resizable.d.ts +1 -17
- package/dist/elements/resizable.js +1 -0
- package/dist/elements/response-stream.js +14 -0
- package/dist/elements/scroll-button.js +1 -0
- package/dist/elements/source.d.ts +0 -17
- package/dist/elements/source.js +1 -0
- package/dist/elements/switch.js +1 -0
- package/dist/elements/tasks.js +1 -0
- package/dist/elements/text-shimmer.js +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.js +1 -0
- package/dist/elements/voice-input.js +1 -0
- package/dist/elements.d.ts +41 -5
- package/dist/index.d.ts +12 -0
- package/dist/index.js +11832 -9790
- package/dist/kitn-chat.es.js +1 -1
- package/dist/llms/llms-full.txt +57 -12
- package/dist/llms/llms.txt +3 -3
- package/dist/mcp.es.js +157 -1
- package/dist/primitives/card-contract.d.ts +20 -4
- package/dist/primitives/card-recovery.d.ts +55 -0
- package/dist/primitives/message-feedback.d.ts +35 -0
- package/dist/primitives/toast-store.d.ts +88 -0
- package/dist/react/index.d.ts +83 -3
- package/dist/react.js +90 -80
- package/dist/register-JyTglR6m.js +1 -0
- package/dist/register-impl-C6wlSsts.js +77 -0
- package/dist/schemas/choice.schema.json +5 -0
- package/dist/schemas/tasks.schema.json +5 -0
- package/dist/ui/tooltip.d.ts +1 -0
- package/frameworks/react/index.tsx +63 -11
- package/llms-full.txt +57 -12
- package/llms.txt +3 -3
- package/package.json +15 -6
- package/src/agent-tooling/mcp/tools/debug.ts +184 -0
- package/src/agent-tooling/mcp/tools/scaffold.ts +133 -1
- 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/element-manifest.json +182 -0
- package/src/elements/element-meta.json +191 -68
- package/src/elements/element-types.d.ts +41 -5
- package/src/elements/framework-usage.json +25 -0
- package/src/elements/message.tsx +27 -45
- package/src/elements/register-impl.ts +3 -0
- package/src/elements/register.ts +9 -0
- 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/dist/elements/chat-types.d.ts +0 -41
- package/dist/elements/css.d.ts +0 -1
- package/dist/elements/default-input.d.ts +0 -40
- package/dist/elements/define.d.ts +0 -42
- package/dist/elements/register-impl.d.ts +0 -0
- package/dist/elements/register.d.ts +0 -3
- package/dist/register-impl-wCsFPoh9.js +0 -77
- package/dist/register-ujhr1nBS.js +0 -1
- /package/dist/elements/{remote.d.ts → compare.d.ts} +0 -0
|
@@ -59,6 +59,9 @@ export function routeCardEvent(policy: CardPolicy | undefined, event: CardEvent)
|
|
|
59
59
|
case 'dismiss':
|
|
60
60
|
p.onDismiss ? p.onDismiss(event.cardId) : warnNoHandler('dismiss');
|
|
61
61
|
break;
|
|
62
|
+
case 'reopen':
|
|
63
|
+
p.onReopen ? p.onReopen(event.cardId) : warnNoHandler('reopen');
|
|
64
|
+
break;
|
|
62
65
|
case 'error':
|
|
63
66
|
p.onError ? p.onError(event.cardId, event.message) : warnNoHandler('error');
|
|
64
67
|
break;
|
|
@@ -65,6 +65,11 @@
|
|
|
65
65
|
"allowOther": {
|
|
66
66
|
"description": "Optional free-text escape ('none of these / specify'). `true` appends a final 'Other…' option; an object customizes its `label`/`placeholder`. Selecting it reveals a text input; the shared Submit button then emits `{ kind:'action', action:'__other__', payload:{ text } }`.",
|
|
67
67
|
"x-kai-control": "allow-other"
|
|
68
|
+
},
|
|
69
|
+
"dismissible": {
|
|
70
|
+
"type": "boolean",
|
|
71
|
+
"default": false,
|
|
72
|
+
"description": "Show a close affordance that emits the `dismiss` verb. The card collapses to a re-openable 'dismissed' stub; the host decides via `onReopen` whether it comes back live or `expired`."
|
|
68
73
|
}
|
|
69
74
|
}
|
|
70
75
|
}
|
|
@@ -73,6 +73,11 @@
|
|
|
73
73
|
"minimum": 1,
|
|
74
74
|
"description": "Optional maximum selectable; further toggles are blocked once reached.",
|
|
75
75
|
"x-kai-select-max": true
|
|
76
|
+
},
|
|
77
|
+
"dismissible": {
|
|
78
|
+
"type": "boolean",
|
|
79
|
+
"default": false,
|
|
80
|
+
"description": "Show a close affordance that emits the `dismiss` verb. The card collapses to a re-openable 'dismissed' stub; the host decides via `onReopen` whether it comes back live or `expired`."
|
|
76
81
|
}
|
|
77
82
|
}
|
|
78
83
|
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Message action-row feedback state — copy + like/dislike — owned ABOVE the
|
|
2
|
+
// per-message `<For>` so a streaming re-render (a fresh `messages` array ref per
|
|
3
|
+
// chunk) never wipes the user's optimistic vote or the transient "copied" check.
|
|
4
|
+
//
|
|
5
|
+
// Both facades (`ChatThread` and the `<kai-message>` element) create one of
|
|
6
|
+
// these and route their action-bar clicks through `handleAction`. Keeping the
|
|
7
|
+
// logic here (not inside the un-unit-testable `defineWebComponent` body) makes
|
|
8
|
+
// the toggle/toast/clipboard behavior directly testable.
|
|
9
|
+
|
|
10
|
+
import { createSignal, onCleanup } from 'solid-js';
|
|
11
|
+
import type { ChatMessage, FeedbackVote } from '../elements/chat-types';
|
|
12
|
+
import { toast } from './toast-store';
|
|
13
|
+
|
|
14
|
+
/** Detail shape emitted by the action row. `state` is present only for the
|
|
15
|
+
* toggleable feedback votes: `'on'` when a vote is set, `'off'` when cleared.
|
|
16
|
+
* Copy / regenerate / edit / custom actions omit it. */
|
|
17
|
+
export interface MessageActionDetail {
|
|
18
|
+
messageId: string;
|
|
19
|
+
action: string;
|
|
20
|
+
state?: 'on' | 'off';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface MessageFeedbackOptions {
|
|
24
|
+
/** Emit the `kai-message-action` detail (facade maps this to `dispatch` /
|
|
25
|
+
* `onMessageAction`). */
|
|
26
|
+
emit: (detail: MessageActionDetail) => void;
|
|
27
|
+
/** How long the copy check stays before auto-clearing. Defaults to 2000ms. */
|
|
28
|
+
copiedDuration?: number;
|
|
29
|
+
/** Container the copy/feedback toasts should be scoped to (the chat, by
|
|
30
|
+
* default) so they appear in-chat rather than at the page top. */
|
|
31
|
+
target?: () => HTMLElement | undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface MessageFeedback {
|
|
35
|
+
/** Resolve the active vote for a message: a controlled `m.feedback` wins,
|
|
36
|
+
* else the facade's own optimistic map. */
|
|
37
|
+
resolveFeedback: (m: Pick<ChatMessage, 'id' | 'feedback'>) => FeedbackVote | undefined;
|
|
38
|
+
/** Whether a message's copy button should currently show its check. */
|
|
39
|
+
isCopied: (id: string) => boolean;
|
|
40
|
+
/** Route a clicked action through copy / vote / passthrough handling. */
|
|
41
|
+
handleAction: (m: Pick<ChatMessage, 'id' | 'content' | 'feedback'>, action: string) => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const DEFAULT_COPIED_DURATION = 2000;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Create the action-row feedback controller for one message list (or one
|
|
48
|
+
* standalone message). Owns the optimistic `feedbackMap` + transient
|
|
49
|
+
* `copiedIds`, resolves the controlled-wins vote, and turns clicks into
|
|
50
|
+
* clipboard writes, toasts, and `kai-message-action` emissions.
|
|
51
|
+
*/
|
|
52
|
+
export function createMessageFeedback(opts: MessageFeedbackOptions): MessageFeedback {
|
|
53
|
+
const [feedbackMap, setFeedbackMap] = createSignal<Record<string, FeedbackVote>>({});
|
|
54
|
+
const [copiedIds, setCopiedIds] = createSignal<Set<string>>(new Set());
|
|
55
|
+
const copiedDuration = opts.copiedDuration ?? DEFAULT_COPIED_DURATION;
|
|
56
|
+
const timers = new Map<string, ReturnType<typeof setTimeout>>();
|
|
57
|
+
|
|
58
|
+
onCleanup(() => {
|
|
59
|
+
timers.forEach((t) => clearTimeout(t));
|
|
60
|
+
timers.clear();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const resolveFeedback: MessageFeedback['resolveFeedback'] = (m) =>
|
|
64
|
+
m.feedback ?? feedbackMap()[m.id];
|
|
65
|
+
|
|
66
|
+
const isCopied: MessageFeedback['isCopied'] = (id) => copiedIds().has(id);
|
|
67
|
+
|
|
68
|
+
const markCopied = (id: string) => {
|
|
69
|
+
setCopiedIds((prev) => {
|
|
70
|
+
const next = new Set(prev);
|
|
71
|
+
next.add(id);
|
|
72
|
+
return next;
|
|
73
|
+
});
|
|
74
|
+
const existing = timers.get(id);
|
|
75
|
+
if (existing) clearTimeout(existing);
|
|
76
|
+
timers.set(id, setTimeout(() => {
|
|
77
|
+
timers.delete(id);
|
|
78
|
+
setCopiedIds((prev) => {
|
|
79
|
+
if (!prev.has(id)) return prev;
|
|
80
|
+
const next = new Set(prev);
|
|
81
|
+
next.delete(id);
|
|
82
|
+
return next;
|
|
83
|
+
});
|
|
84
|
+
}, copiedDuration));
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const setVote = (id: string, vote: FeedbackVote | undefined) => {
|
|
88
|
+
setFeedbackMap((prev) => {
|
|
89
|
+
const next = { ...prev };
|
|
90
|
+
if (vote === undefined) delete next[id];
|
|
91
|
+
else next[id] = vote;
|
|
92
|
+
return next;
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const handleAction: MessageFeedback['handleAction'] = (m, action) => {
|
|
97
|
+
if (action === 'copy') {
|
|
98
|
+
// Clipboard may be unavailable (insecure context / jsdom); fail soft.
|
|
99
|
+
try { navigator.clipboard?.writeText(m.content); } catch { /* ignore */ }
|
|
100
|
+
markCopied(m.id);
|
|
101
|
+
toast('Copied to clipboard', { target: opts.target?.() });
|
|
102
|
+
opts.emit({ messageId: m.id, action });
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (action === 'like' || action === 'dislike') {
|
|
106
|
+
const current = resolveFeedback(m);
|
|
107
|
+
if (current === action) {
|
|
108
|
+
// Re-tap clears the vote — no toast on un-vote.
|
|
109
|
+
setVote(m.id, undefined);
|
|
110
|
+
opts.emit({ messageId: m.id, action, state: 'off' });
|
|
111
|
+
} else {
|
|
112
|
+
setVote(m.id, action);
|
|
113
|
+
toast('Thanks for your feedback', { target: opts.target?.() });
|
|
114
|
+
opts.emit({ messageId: m.id, action, state: 'on' });
|
|
115
|
+
}
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
// regenerate / edit / custom — passthrough, no state.
|
|
119
|
+
opts.emit({ messageId: m.id, action });
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
return { resolveFeedback, isCopied, handleAction };
|
|
123
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// Module-level toast store + the imperative `toast()` API.
|
|
2
|
+
//
|
|
3
|
+
// This is the PRIMARY way consumers raise a toast: `toast('Saved')`,
|
|
4
|
+
// `toast.success('Copied')`, `toast.dismiss(id)`. The store is a single
|
|
5
|
+
// reactive list held in a long-lived `createRoot` (so its reactivity survives
|
|
6
|
+
// outside any component), and `ensureMounted()` lazily creates exactly ONE
|
|
7
|
+
// `<kai-toast-region>` on `document.body` the first time a toast is raised,
|
|
8
|
+
// binding the list to its `toasts` property. The region is a real `kai-*`
|
|
9
|
+
// element, so it carries its own shadow root + the shared kit stylesheet — it's
|
|
10
|
+
// viewport-positioned AND fully kit-styled, never a raw div.
|
|
11
|
+
//
|
|
12
|
+
// SSR-safe: every DOM touch is guarded by `typeof document`. On the server,
|
|
13
|
+
// raising a toast is an inert no-op (the store updates, nothing mounts).
|
|
14
|
+
|
|
15
|
+
import { createRoot, createSignal } from 'solid-js';
|
|
16
|
+
import { createStore, produce } from 'solid-js/store';
|
|
17
|
+
import type { ToastPosition } from '../components/toast';
|
|
18
|
+
|
|
19
|
+
export type ToastVariant = 'neutral' | 'success';
|
|
20
|
+
|
|
21
|
+
export interface ToastConfig {
|
|
22
|
+
stack?: 'expanded' | 'collapsed';
|
|
23
|
+
position?: ToastPosition;
|
|
24
|
+
max?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Module-level config the imperative singleton regions inherit. Defaults match
|
|
28
|
+
// the element's own defaults, so an un-configured app behaves exactly as before.
|
|
29
|
+
let toastConfig: ToastConfig = {};
|
|
30
|
+
|
|
31
|
+
/** Apply the current config to a region element (attributes for scalars). */
|
|
32
|
+
function applyConfig(el: HTMLElement): void {
|
|
33
|
+
if (toastConfig.stack) el.setAttribute('stack', toastConfig.stack);
|
|
34
|
+
if (toastConfig.position) el.setAttribute('position', toastConfig.position);
|
|
35
|
+
if (toastConfig.max !== undefined) el.setAttribute('max', String(toastConfig.max));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Configure the imperative `toast()` singleton — call once at app start.
|
|
40
|
+
* `toast.success('…')` has no element to set a prop on, so this is how you opt
|
|
41
|
+
* the auto-mounted region into collapsed stacking / a position / a max. Updates
|
|
42
|
+
* any already-mounted regions too, so call order doesn't matter.
|
|
43
|
+
*/
|
|
44
|
+
export function configureToasts(config: ToastConfig): void {
|
|
45
|
+
toastConfig = { ...toastConfig, ...config };
|
|
46
|
+
if (typeof document === 'undefined') return;
|
|
47
|
+
document.querySelectorAll('kai-toast-region').forEach((el) => applyConfig(el as HTMLElement));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** An action button rendered inside the toast. Returning `false` from
|
|
51
|
+
* `onAction` keeps the toast open (e.g. to show a follow-up); any other
|
|
52
|
+
* return value dismisses it. */
|
|
53
|
+
export interface ToastAction {
|
|
54
|
+
label: string;
|
|
55
|
+
onAction: () => void | false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface ToastItem {
|
|
59
|
+
id: string;
|
|
60
|
+
message: string;
|
|
61
|
+
variant?: ToastVariant;
|
|
62
|
+
action?: ToastAction;
|
|
63
|
+
/** Auto-dismiss delay in ms. `0` = sticky (never auto-dismisses). When an
|
|
64
|
+
* `action` is present the effective floor is 4000ms so it stays long enough
|
|
65
|
+
* to act on. Defaults to 2000ms. */
|
|
66
|
+
duration?: number;
|
|
67
|
+
/** Whether the × close affordance is shown. Defaults to `true`. */
|
|
68
|
+
dismissible?: boolean;
|
|
69
|
+
/** Container to scope this toast WITHIN — it floats anchored to that element's
|
|
70
|
+
* bounds instead of the viewport. Omit for a global, viewport-anchored toast.
|
|
71
|
+
* The chat targets itself by default so its copy/feedback toasts stay in-chat. */
|
|
72
|
+
target?: HTMLElement;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Options accepted by `toast()` — everything but the message. Pass `id` to
|
|
76
|
+
* update an existing toast in place. */
|
|
77
|
+
export interface ToastOptions {
|
|
78
|
+
id?: string;
|
|
79
|
+
variant?: ToastVariant;
|
|
80
|
+
action?: ToastAction;
|
|
81
|
+
duration?: number;
|
|
82
|
+
dismissible?: boolean;
|
|
83
|
+
/** Scope this toast to a container's bounds (e.g. a chat) instead of the
|
|
84
|
+
* viewport. Omit for a global, viewport-anchored toast. */
|
|
85
|
+
target?: HTMLElement;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Handle returned from `toast()` for imperative control. */
|
|
89
|
+
export interface ToastHandle {
|
|
90
|
+
id: string;
|
|
91
|
+
dismiss: () => void;
|
|
92
|
+
update: (patch: Partial<Omit<ToastItem, 'id'>>) => void;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Default auto-dismiss delay. Long enough to read + reach before it leaves. */
|
|
96
|
+
export const DEFAULT_TOAST_DURATION = 5000;
|
|
97
|
+
/** Minimum auto-dismiss delay when the toast carries an action (e.g. Undo) — it
|
|
98
|
+
* has to stay up long enough to actually act on. */
|
|
99
|
+
export const ACTION_TOAST_FLOOR = 7000;
|
|
100
|
+
|
|
101
|
+
// ── The reactive store ──────────────────────────────────────────────────────
|
|
102
|
+
// Held in a never-disposed root so the signal/store graph stays live for the
|
|
103
|
+
// lifetime of the page, independent of any component.
|
|
104
|
+
const { toasts, setToasts, mounted, setMounted } = createRoot(() => {
|
|
105
|
+
const [list, setList] = createStore<ToastItem[]>([]);
|
|
106
|
+
const [isMounted, setIsMounted] = createSignal(false);
|
|
107
|
+
return { toasts: list, setToasts: setList, mounted: isMounted, setMounted: setIsMounted };
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
/** The live toast list (reactive). The region facade binds to this. */
|
|
111
|
+
export function getToasts(): ToastItem[] {
|
|
112
|
+
return toasts;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let counter = 0;
|
|
116
|
+
function nextId(): string {
|
|
117
|
+
counter += 1;
|
|
118
|
+
return `toast-${counter}`;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Resolve the effective duration, applying the action floor. */
|
|
122
|
+
function resolveDuration(item: Pick<ToastItem, 'duration' | 'action'>): number {
|
|
123
|
+
const base = item.duration ?? DEFAULT_TOAST_DURATION;
|
|
124
|
+
if (base === 0) return 0; // explicit sticky wins
|
|
125
|
+
if (item.action) return Math.max(base, ACTION_TOAST_FLOOR);
|
|
126
|
+
return base;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Lazily create the single `<kai-toast-region>` host on `document.body` and
|
|
131
|
+
* bind the store to its `toasts` property. Idempotent + SSR-safe. The element
|
|
132
|
+
* upgrade (its `defineWebComponent` registration) happens when the elements
|
|
133
|
+
* bundle loads; setting the property before/after upgrade both work because
|
|
134
|
+
* `customElement` reflects late-set properties.
|
|
135
|
+
*/
|
|
136
|
+
// One region per distinct target (the `null` key = the global / viewport region).
|
|
137
|
+
// Every region binds the SAME store proxy and filters to its own target, so a
|
|
138
|
+
// toast routes to the region for its `target`.
|
|
139
|
+
const regions = new Map<HTMLElement | null, HTMLElement>();
|
|
140
|
+
|
|
141
|
+
export function ensureMounted(target: HTMLElement | null = null): HTMLElement | undefined {
|
|
142
|
+
if (typeof document === 'undefined') return undefined;
|
|
143
|
+
const cached = regions.get(target);
|
|
144
|
+
if (cached && cached.isConnected) return cached;
|
|
145
|
+
const el = document.createElement('kai-toast-region') as HTMLElement;
|
|
146
|
+
// Append FIRST so the element upgrades, THEN bind. Setting a property before
|
|
147
|
+
// upgrade loses it: component-register resets every prop in the constructor on
|
|
148
|
+
// upgrade (the same pre-upgrade clobber that bites <kai-chat>), so a pre-append
|
|
149
|
+
// `el.toasts = …` is wiped and the first toast never renders.
|
|
150
|
+
document.body.appendChild(el);
|
|
151
|
+
(el as unknown as { toasts: ToastItem[] }).toasts = toasts as ToastItem[];
|
|
152
|
+
if (target) (el as unknown as { target: HTMLElement }).target = target;
|
|
153
|
+
applyConfig(el); // inherit stack/position/max from configureToasts()
|
|
154
|
+
regions.set(target, el);
|
|
155
|
+
setMounted(true);
|
|
156
|
+
return el;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Test-only: whether `ensureMounted` has run. */
|
|
160
|
+
export function isToastRegionMounted(): boolean {
|
|
161
|
+
return mounted();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function upsert(item: ToastItem): void {
|
|
165
|
+
const idx = toasts.findIndex((t) => t.id === item.id);
|
|
166
|
+
if (idx >= 0) {
|
|
167
|
+
setToasts(idx, item);
|
|
168
|
+
} else {
|
|
169
|
+
setToasts(produce((list) => { list.push(item); }));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function dismiss(id: string): void {
|
|
174
|
+
setToasts((list) => list.filter((t) => t.id !== id));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function makeHandle(id: string): ToastHandle {
|
|
178
|
+
return {
|
|
179
|
+
id,
|
|
180
|
+
dismiss: () => dismiss(id),
|
|
181
|
+
update: (patch) => {
|
|
182
|
+
const idx = toasts.findIndex((t) => t.id === id);
|
|
183
|
+
if (idx >= 0) setToasts(idx, (prev) => ({ ...prev, ...patch }));
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Internal: raise/refresh a toast of a given variant. */
|
|
189
|
+
function raise(message: string, opts: ToastOptions | undefined, variant: ToastVariant): ToastHandle {
|
|
190
|
+
ensureMounted(opts?.target ?? null);
|
|
191
|
+
const id = opts?.id ?? nextId();
|
|
192
|
+
const item: ToastItem = {
|
|
193
|
+
id,
|
|
194
|
+
message,
|
|
195
|
+
variant: opts?.variant ?? variant,
|
|
196
|
+
action: opts?.action,
|
|
197
|
+
duration: opts?.duration,
|
|
198
|
+
dismissible: opts?.dismissible,
|
|
199
|
+
target: opts?.target,
|
|
200
|
+
};
|
|
201
|
+
upsert(item);
|
|
202
|
+
return makeHandle(id);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface ToastFn {
|
|
206
|
+
(message: string, opts?: ToastOptions): ToastHandle;
|
|
207
|
+
/** Raise a success (emerald check) toast. */
|
|
208
|
+
success: (message: string, opts?: ToastOptions) => ToastHandle;
|
|
209
|
+
/** Dismiss a toast by id. */
|
|
210
|
+
dismiss: (id: string) => void;
|
|
211
|
+
/** Dismiss every active toast. */
|
|
212
|
+
clear: () => void;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Raise a transient toast. Returns a `{ id, dismiss, update }` handle.
|
|
217
|
+
*
|
|
218
|
+
* ```ts
|
|
219
|
+
* toast('Copied to clipboard');
|
|
220
|
+
* toast.success('Saved');
|
|
221
|
+
* const t = toast('Working…', { duration: 0 });
|
|
222
|
+
* t.update({ message: 'Done', variant: 'success', duration: 2000 });
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
export const toast: ToastFn = Object.assign(
|
|
226
|
+
(message: string, opts?: ToastOptions) => raise(message, opts, 'neutral'),
|
|
227
|
+
{
|
|
228
|
+
success: (message: string, opts?: ToastOptions) => raise(message, opts, 'success'),
|
|
229
|
+
dismiss,
|
|
230
|
+
clear: () => setToasts([]),
|
|
231
|
+
},
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
// Re-export for the region facade so the effective-duration rule lives in one place.
|
|
235
|
+
export { resolveDuration };
|
package/src/ui/tooltip.tsx
CHANGED
|
@@ -4,10 +4,10 @@ import { cn } from '../utils/cn';
|
|
|
4
4
|
import { useChatConfig } from '../primitives/chat-config';
|
|
5
5
|
import { createPresence, usePosition, useDismiss, As } from './overlay';
|
|
6
6
|
|
|
7
|
-
export interface TooltipProps { content: string; children: JSX.Element; class?: string; openDelay?: number; }
|
|
7
|
+
export interface TooltipProps { content: string; children: JSX.Element; class?: string; openDelay?: number; dismissOnClick?: boolean; }
|
|
8
8
|
|
|
9
9
|
export function Tooltip(props: TooltipProps) {
|
|
10
|
-
const [local] = splitProps(props, ['content', 'children', 'class', 'openDelay']);
|
|
10
|
+
const [local] = splitProps(props, ['content', 'children', 'class', 'openDelay', 'dismissOnClick']);
|
|
11
11
|
const config = useChatConfig();
|
|
12
12
|
const id = createUniqueId();
|
|
13
13
|
const [open, setOpen] = createSignal(false);
|
|
@@ -25,6 +25,10 @@ export function Tooltip(props: TooltipProps) {
|
|
|
25
25
|
};
|
|
26
26
|
const hide = () => { clearTimeout(timer); setOpen(false); };
|
|
27
27
|
const maybeHide = () => { if (!pointerInside() && !focusInside()) hide(); };
|
|
28
|
+
// Action-style tooltips should dismiss when their trigger is clicked: the pointer
|
|
29
|
+
// never "leaves", so reset the inside flags and force-close until the next genuine
|
|
30
|
+
// hover/focus. Opt out with dismissOnClick={false}.
|
|
31
|
+
const dismiss = () => { if (local.dismissOnClick === false) return; setPointerInside(false); setFocusInside(false); hide(); };
|
|
28
32
|
onCleanup(() => clearTimeout(timer));
|
|
29
33
|
|
|
30
34
|
const presence = createPresence(open);
|
|
@@ -39,6 +43,8 @@ export function Tooltip(props: TooltipProps) {
|
|
|
39
43
|
aria-describedby={open() ? id : undefined}
|
|
40
44
|
onPointerEnter={() => { setPointerInside(true); show(local.openDelay ?? 600); }}
|
|
41
45
|
onPointerLeave={() => { setPointerInside(false); maybeHide(); }}
|
|
46
|
+
onPointerDown={dismiss}
|
|
47
|
+
onClick={dismiss}
|
|
42
48
|
onFocusIn={() => { setFocusInside(true); show(); }}
|
|
43
49
|
onFocusOut={(e: FocusEvent) => { const t = triggerEl(); if (t && t.contains(e.relatedTarget as Node)) return; setFocusInside(false); maybeHide(); }}
|
|
44
50
|
>
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { ToolPart } from '../components/tool';
|
|
2
|
-
import { AttachmentData } from '../components/attachments';
|
|
3
|
-
/** The five built-in action buttons (each carries its own curated icon + label). */
|
|
4
|
-
export type ChatMessageAction = 'copy' | 'like' | 'dislike' | 'regenerate' | 'edit';
|
|
5
|
-
/** A host-defined action button. `icon` is a curated registry name (see
|
|
6
|
-
* `src/ui/action-icons.ts`); unknown/absent icons render label-only. */
|
|
7
|
-
export interface CustomAction {
|
|
8
|
-
/** Emitted as the `kai-message-action` detail `action` when clicked. */
|
|
9
|
-
id: string;
|
|
10
|
-
/** Visible/`aria-label` text. */
|
|
11
|
-
label: string;
|
|
12
|
-
/** A curated icon name from the action-icon registry. */
|
|
13
|
-
icon?: string;
|
|
14
|
-
/** Tooltip text shown on hover. Defaults to `label` when omitted. */
|
|
15
|
-
tooltip?: string;
|
|
16
|
-
}
|
|
17
|
-
/** The speaker avatar for a message row. (Mirrors the `…Data` convention of
|
|
18
|
-
* `AttachmentData`; named to avoid clashing with the `MessageAvatar` component.) */
|
|
19
|
-
export interface AvatarData {
|
|
20
|
-
/** Image URL. When present, renders an `<img>`. */
|
|
21
|
-
src?: string;
|
|
22
|
-
/** Initials/short text shown when there is no `src`. */
|
|
23
|
-
fallback?: string;
|
|
24
|
-
/** Alt text for the image. */
|
|
25
|
-
alt?: string;
|
|
26
|
-
}
|
|
27
|
-
export interface ChatMessage {
|
|
28
|
-
id: string;
|
|
29
|
-
role: 'user' | 'assistant';
|
|
30
|
-
content: string;
|
|
31
|
-
reasoning?: {
|
|
32
|
-
text: string;
|
|
33
|
-
label?: string;
|
|
34
|
-
};
|
|
35
|
-
tools?: ToolPart[];
|
|
36
|
-
attachments?: AttachmentData[];
|
|
37
|
-
/** Action buttons under the message — built-in names and/or custom descriptors. */
|
|
38
|
-
actions?: (ChatMessageAction | CustomAction)[];
|
|
39
|
-
/** Optional speaker avatar shown to the left of the message column. */
|
|
40
|
-
avatar?: AvatarData;
|
|
41
|
-
}
|
package/dist/elements/css.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const ELEMENT_CSS: string;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { SlashCommandItem } from '../components/slash-command';
|
|
2
|
-
import { AttachmentData } from '../components/attachments';
|
|
3
|
-
import { CustomAction } from './chat-types';
|
|
4
|
-
export interface DefaultPromptInputProps {
|
|
5
|
-
value: string;
|
|
6
|
-
placeholder?: string;
|
|
7
|
-
disabled?: boolean;
|
|
8
|
-
loading?: boolean;
|
|
9
|
-
suggestions?: string[];
|
|
10
|
-
/** Attachments staged in the input. Provide `onAttachmentsChange` to enable
|
|
11
|
-
* the attach button + removable previews. */
|
|
12
|
-
attachments?: AttachmentData[];
|
|
13
|
-
/** Show a Search (Globe) button in the left toolbar; calls `onSearch`. */
|
|
14
|
-
search?: boolean;
|
|
15
|
-
/** Show a Voice (Mic) button in the left toolbar; calls `onVoice`. */
|
|
16
|
-
voice?: boolean;
|
|
17
|
-
/** Slash commands — when set, typing `/` opens the command palette. */
|
|
18
|
-
slashCommands?: SlashCommandItem[];
|
|
19
|
-
/** Currently-active command ids (highlighted in the palette). */
|
|
20
|
-
slashActiveIds?: string[];
|
|
21
|
-
/** Single-line palette rows. */
|
|
22
|
-
slashCompact?: boolean;
|
|
23
|
-
onValueChange: (v: string) => void;
|
|
24
|
-
onSubmit: () => void;
|
|
25
|
-
onSuggestionClick: (v: string) => void;
|
|
26
|
-
onAttachmentsChange?: (attachments: AttachmentData[]) => void;
|
|
27
|
-
onSearch?: () => void;
|
|
28
|
-
onVoice?: () => void;
|
|
29
|
-
onSlashSelect?: (command: SlashCommandItem) => void;
|
|
30
|
-
/** When `true` and `loading` is also `true`, the send button is replaced by
|
|
31
|
-
* a Stop button that calls `onStop`. */
|
|
32
|
-
stoppable?: boolean;
|
|
33
|
-
/** Called when the user clicks the Stop button. */
|
|
34
|
-
onStop?: () => void;
|
|
35
|
-
/** Custom toolbar action buttons declared as `<kai-action>` light-DOM children. */
|
|
36
|
-
toolbarActions?: CustomAction[];
|
|
37
|
-
/** Called when a custom toolbar action button is clicked, with the action id. */
|
|
38
|
-
onAction?: (id: string) => void;
|
|
39
|
-
}
|
|
40
|
-
export declare function DefaultPromptInput(props: DefaultPromptInputProps): import("solid-js").JSX.Element;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { JSX } from 'solid-js';
|
|
2
|
-
/**
|
|
3
|
-
* Context handed to every element facade. `E` is the element's event map —
|
|
4
|
-
* `{ eventName: detailType }` — which types `dispatch` so a facade can only fire
|
|
5
|
-
* its declared events with the right `detail` shape.
|
|
6
|
-
*/
|
|
7
|
-
export interface WebComponentContext<E = Record<string, unknown>> {
|
|
8
|
-
/** The custom-element host node. */
|
|
9
|
-
element: HTMLElement;
|
|
10
|
-
/** Fire a non-bubbling, non-composed CustomEvent off the host. Consumers
|
|
11
|
-
* listen directly on the element (`el.addEventListener(...)`). Typed by the
|
|
12
|
-
* element's event map `E`. */
|
|
13
|
-
dispatch: <K extends keyof E & string>(type: K, detail?: E[K]) => void;
|
|
14
|
-
/**
|
|
15
|
-
* Resolve a boolean flag from a prop the way HTML authors expect.
|
|
16
|
-
*
|
|
17
|
-
* `component-register` parses a *bare* boolean attribute (`<el removable>`) to
|
|
18
|
-
* `undefined`, not `true` — so a facade can't rely on the prop value alone.
|
|
19
|
-
* `flag('removable')` returns ON when the property is `true`, OR when the
|
|
20
|
-
* matching attribute is present and not explicitly `="false"`. So all of
|
|
21
|
-
* `<el removable>`, `<el removable="true">`, and `el.removable = true` turn it
|
|
22
|
-
* on; `<el removable="false">`, absent, and `el.removable = false` turn it off.
|
|
23
|
-
*
|
|
24
|
-
* `name` is the camelCase prop name; the matching kebab attribute is derived.
|
|
25
|
-
*/
|
|
26
|
-
flag: (name: string) => boolean;
|
|
27
|
-
}
|
|
28
|
-
type FacadeComponent<P, E> = (props: P, ctx: WebComponentContext<E>) => JSX.Element;
|
|
29
|
-
/**
|
|
30
|
-
* Register a Solid facade as a Shadow-DOM custom element.
|
|
31
|
-
*
|
|
32
|
-
* - Renders into the element's shadow root (solid-element's default), with the
|
|
33
|
-
* compiled kit CSS injected via a `<style>` so Tailwind classes apply inside.
|
|
34
|
-
* - Creates a portal mount node inside the shadow root and provides it through
|
|
35
|
-
* `ChatConfig` so the kit's overlays stay inside the shadow root.
|
|
36
|
-
* - Gives the facade a `dispatch(type, detail)` helper that fires non-bubbling,
|
|
37
|
-
* non-composed CustomEvents off the host element (consumers listen directly on
|
|
38
|
-
* the element, so bubbling/composed would only cause consumer collisions).
|
|
39
|
-
* - Idempotent: redefining an already-registered tag is a no-op.
|
|
40
|
-
*/
|
|
41
|
-
export declare function defineWebComponent<P extends Record<string, unknown>, E = Record<string, unknown>>(tag: string, propDefaults: P, Facade: FacadeComponent<P, E>): void;
|
|
42
|
-
export {};
|
|
File without changes
|