@smart-cloud/ai-kit-ui 1.1.15 → 1.1.16
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/dist/index.cjs +9 -9
- package/dist/index.js +9 -9
- package/package.json +2 -2
- package/src/ShadowBoundary.tsx +5 -10
- package/src/ai-chatbot/AiChatbot.tsx +6 -8
- package/src/withAiKitShell.tsx +26 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smart-cloud/ai-kit-ui",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@emotion/cache": "^11.14.0",
|
|
21
21
|
"@emotion/react": "^11.14.0",
|
|
22
22
|
"@mantine/colors-generator": "^8.3.13",
|
|
23
|
-
"@smart-cloud/ai-kit-core": "^1.1.
|
|
23
|
+
"@smart-cloud/ai-kit-core": "^1.1.7",
|
|
24
24
|
"@smart-cloud/wpsuite-core": "^2.0.5",
|
|
25
25
|
"@tabler/icons-react": "^3.36.1",
|
|
26
26
|
"chroma-js": "^3.2.0",
|
package/src/ShadowBoundary.tsx
CHANGED
|
@@ -9,9 +9,6 @@ export type ShadowBoundaryProps = {
|
|
|
9
9
|
/** Stylesheets to inject into the shadow root (as <link rel="stylesheet">). */
|
|
10
10
|
stylesheets: string[];
|
|
11
11
|
|
|
12
|
-
/** Optional class name applied to the host element. */
|
|
13
|
-
className?: string;
|
|
14
|
-
|
|
15
12
|
/** ID of the element inside the shadow root used as the portal target. */
|
|
16
13
|
rootElementId: string;
|
|
17
14
|
|
|
@@ -88,7 +85,6 @@ function installAiKitPropertyRegistry() {
|
|
|
88
85
|
|
|
89
86
|
export function ShadowBoundary({
|
|
90
87
|
stylesheets,
|
|
91
|
-
className,
|
|
92
88
|
children,
|
|
93
89
|
rootElementId,
|
|
94
90
|
mode = "local",
|
|
@@ -207,7 +203,6 @@ export function ShadowBoundary({
|
|
|
207
203
|
return (
|
|
208
204
|
<div
|
|
209
205
|
ref={hostRef}
|
|
210
|
-
className={className}
|
|
211
206
|
style={{
|
|
212
207
|
outline: "none",
|
|
213
208
|
boxShadow: "none",
|
|
@@ -216,11 +211,11 @@ export function ShadowBoundary({
|
|
|
216
211
|
>
|
|
217
212
|
{portalTarget && shadowRoot && emotionCache
|
|
218
213
|
? createPortal(
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
214
|
+
<CacheProvider value={emotionCache}>
|
|
215
|
+
{children({ rootElement: portalTarget, shadowRoot })}
|
|
216
|
+
</CacheProvider>,
|
|
217
|
+
portalTarget,
|
|
218
|
+
)
|
|
224
219
|
: null}
|
|
225
220
|
</div>
|
|
226
221
|
);
|
|
@@ -53,9 +53,8 @@ const TWENTY_FOUR_HOURS_MS = 24 * 60 * 60 * 1000;
|
|
|
53
53
|
|
|
54
54
|
// New: history storage support
|
|
55
55
|
const DEFAULT_HISTORY_STORAGE: HistoryStorageMode = "localstorage";
|
|
56
|
-
const HISTORY_STORAGE_KEY = `ai-kit-chatbot-history-v1:${
|
|
57
|
-
|
|
58
|
-
}`;
|
|
56
|
+
const HISTORY_STORAGE_KEY = `ai-kit-chatbot-history-v1:${typeof window !== "undefined" ? window.location.hostname : "unknown"
|
|
57
|
+
}`;
|
|
59
58
|
|
|
60
59
|
export const DEFAULT_CHATBOT_LABELS: Required<AiChatbotLabels> = {
|
|
61
60
|
modalTitle: "AI Assistant",
|
|
@@ -216,7 +215,6 @@ const AiChatbotBase: FC<AiChatbotProps & AiKitShellInjectedProps> = (props) => {
|
|
|
216
215
|
openButtonIcon,
|
|
217
216
|
showOpenButtonTitle = true,
|
|
218
217
|
showOpenButtonIcon = true,
|
|
219
|
-
className,
|
|
220
218
|
colorMode,
|
|
221
219
|
language,
|
|
222
220
|
onClose,
|
|
@@ -346,8 +344,8 @@ const AiChatbotBase: FC<AiChatbotProps & AiKitShellInjectedProps> = (props) => {
|
|
|
346
344
|
const rootClassName = useMemo(() => {
|
|
347
345
|
const base = "ai-docs-ask";
|
|
348
346
|
const pos = `ai-open-btn--${openButtonPosition}`;
|
|
349
|
-
return
|
|
350
|
-
}, [
|
|
347
|
+
return `${base} ${pos}`;
|
|
348
|
+
}, [openButtonPosition]);
|
|
351
349
|
|
|
352
350
|
const adjustChatHeight = useCallback(() => {
|
|
353
351
|
const el = chatContainerRef.current;
|
|
@@ -597,7 +595,7 @@ const AiChatbotBase: FC<AiChatbotProps & AiKitShellInjectedProps> = (props) => {
|
|
|
597
595
|
try {
|
|
598
596
|
const activeSessionId =
|
|
599
597
|
sessionRef.current &&
|
|
600
|
-
|
|
598
|
+
Date.now() - sessionRef.current.storedAt < TWENTY_FOUR_HOURS_MS
|
|
601
599
|
? sessionRef.current.id
|
|
602
600
|
: undefined;
|
|
603
601
|
if (!activeSessionId) return;
|
|
@@ -682,7 +680,7 @@ const AiChatbotBase: FC<AiChatbotProps & AiKitShellInjectedProps> = (props) => {
|
|
|
682
680
|
try {
|
|
683
681
|
const activeSessionId =
|
|
684
682
|
sessionRef.current &&
|
|
685
|
-
|
|
683
|
+
Date.now() - sessionRef.current.storedAt < TWENTY_FOUR_HOURS_MS
|
|
686
684
|
? sessionRef.current.id
|
|
687
685
|
: undefined;
|
|
688
686
|
|
package/src/withAiKitShell.tsx
CHANGED
|
@@ -47,8 +47,7 @@ export function withAiKitShell<P extends object>(
|
|
|
47
47
|
colorMode,
|
|
48
48
|
primaryColor,
|
|
49
49
|
primaryShade,
|
|
50
|
-
|
|
51
|
-
innerCSS,
|
|
50
|
+
themeOverrides,
|
|
52
51
|
language,
|
|
53
52
|
direction,
|
|
54
53
|
} = { ...props, ...propOverrides } as AiWorkerProps & P;
|
|
@@ -126,19 +125,19 @@ export function withAiKitShell<P extends object>(
|
|
|
126
125
|
].includes(primaryColor) && { primaryColor }),
|
|
127
126
|
...(primaryShade &&
|
|
128
127
|
Object.keys(primaryShade).length > 0 && {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
128
|
+
primaryShade: {
|
|
129
|
+
light:
|
|
130
|
+
primaryShade.light ??
|
|
131
|
+
(typeof DEFAULT_THEME.primaryShade === "object"
|
|
132
|
+
? DEFAULT_THEME.primaryShade.light
|
|
133
|
+
: (DEFAULT_THEME.primaryShade ?? 6)),
|
|
134
|
+
dark:
|
|
135
|
+
primaryShade.dark ??
|
|
136
|
+
(typeof DEFAULT_THEME.primaryShade === "object"
|
|
137
|
+
? DEFAULT_THEME.primaryShade.dark
|
|
138
|
+
: (DEFAULT_THEME.primaryShade ?? 6)),
|
|
139
|
+
},
|
|
140
|
+
}),
|
|
142
141
|
components: {
|
|
143
142
|
Button: {
|
|
144
143
|
styles: { root: { borderRadius: "inherit" } },
|
|
@@ -175,9 +174,9 @@ export function withAiKitShell<P extends object>(
|
|
|
175
174
|
},
|
|
176
175
|
});
|
|
177
176
|
|
|
178
|
-
const
|
|
179
|
-
return
|
|
180
|
-
}, [
|
|
177
|
+
const themeOverridesHash = useMemo(() => {
|
|
178
|
+
return themeOverrides ? hashStringDjb2(themeOverrides) : "";
|
|
179
|
+
}, [themeOverrides]);
|
|
181
180
|
|
|
182
181
|
const injectStyle = useCallback(
|
|
183
182
|
(rootElement: HTMLDivElement) => {
|
|
@@ -185,25 +184,25 @@ export function withAiKitShell<P extends object>(
|
|
|
185
184
|
STYLE_TEXT_ID,
|
|
186
185
|
) as HTMLStyleElement | null;
|
|
187
186
|
|
|
188
|
-
if (
|
|
187
|
+
if (themeOverrides) {
|
|
189
188
|
if (!existingStyle) {
|
|
190
189
|
const s = rootElement.ownerDocument.createElement("style");
|
|
191
190
|
s.id = STYLE_TEXT_ID;
|
|
192
|
-
s.setAttribute("data-hash",
|
|
193
|
-
s.textContent =
|
|
191
|
+
s.setAttribute("data-hash", themeOverridesHash);
|
|
192
|
+
s.textContent = themeOverrides;
|
|
194
193
|
rootElement.appendChild(s);
|
|
195
194
|
} else {
|
|
196
195
|
const prevHash = existingStyle.getAttribute("data-hash") || "";
|
|
197
|
-
if (prevHash !==
|
|
198
|
-
existingStyle.setAttribute("data-hash",
|
|
199
|
-
existingStyle.textContent =
|
|
196
|
+
if (prevHash !== themeOverridesHash) {
|
|
197
|
+
existingStyle.setAttribute("data-hash", themeOverridesHash);
|
|
198
|
+
existingStyle.textContent = themeOverrides;
|
|
200
199
|
}
|
|
201
200
|
}
|
|
202
201
|
} else if (existingStyle) {
|
|
203
202
|
existingStyle.remove();
|
|
204
203
|
}
|
|
205
204
|
},
|
|
206
|
-
[
|
|
205
|
+
[themeOverrides, themeOverridesHash],
|
|
207
206
|
);
|
|
208
207
|
|
|
209
208
|
return (
|
|
@@ -212,7 +211,6 @@ export function withAiKitShell<P extends object>(
|
|
|
212
211
|
variation={variation}
|
|
213
212
|
overlayRootId="ai-kit-overlay-root"
|
|
214
213
|
stylesheets={stylesheets}
|
|
215
|
-
className={className}
|
|
216
214
|
rootElementId={
|
|
217
215
|
variation === "modal" && !showOpenButton
|
|
218
216
|
? "ai-kit-portal-root"
|
|
@@ -258,8 +256,7 @@ export function withAiKitShell<P extends object>(
|
|
|
258
256
|
);
|
|
259
257
|
};
|
|
260
258
|
|
|
261
|
-
Wrapped.displayName = `withAiKitShell(${
|
|
262
|
-
|
|
263
|
-
})`;
|
|
259
|
+
Wrapped.displayName = `withAiKitShell(${RootComponent.displayName ?? RootComponent.name ?? "Component"
|
|
260
|
+
})`;
|
|
264
261
|
return Wrapped;
|
|
265
262
|
}
|