@smart-cloud/ai-kit-ui 1.1.14 → 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 -31
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;
|
|
@@ -116,8 +115,6 @@ export function withAiKitShell<P extends object>(
|
|
|
116
115
|
});
|
|
117
116
|
}
|
|
118
117
|
|
|
119
|
-
console.log("withAiKitShell rendered", { customColors });
|
|
120
|
-
|
|
121
118
|
const theme = createTheme({
|
|
122
119
|
respectReducedMotion: true,
|
|
123
120
|
...(customColors && { colors: customColors }),
|
|
@@ -128,19 +125,19 @@ export function withAiKitShell<P extends object>(
|
|
|
128
125
|
].includes(primaryColor) && { primaryColor }),
|
|
129
126
|
...(primaryShade &&
|
|
130
127
|
Object.keys(primaryShade).length > 0 && {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
+
}),
|
|
144
141
|
components: {
|
|
145
142
|
Button: {
|
|
146
143
|
styles: { root: { borderRadius: "inherit" } },
|
|
@@ -177,9 +174,9 @@ export function withAiKitShell<P extends object>(
|
|
|
177
174
|
},
|
|
178
175
|
});
|
|
179
176
|
|
|
180
|
-
const
|
|
181
|
-
return
|
|
182
|
-
}, [
|
|
177
|
+
const themeOverridesHash = useMemo(() => {
|
|
178
|
+
return themeOverrides ? hashStringDjb2(themeOverrides) : "";
|
|
179
|
+
}, [themeOverrides]);
|
|
183
180
|
|
|
184
181
|
const injectStyle = useCallback(
|
|
185
182
|
(rootElement: HTMLDivElement) => {
|
|
@@ -187,25 +184,25 @@ export function withAiKitShell<P extends object>(
|
|
|
187
184
|
STYLE_TEXT_ID,
|
|
188
185
|
) as HTMLStyleElement | null;
|
|
189
186
|
|
|
190
|
-
if (
|
|
187
|
+
if (themeOverrides) {
|
|
191
188
|
if (!existingStyle) {
|
|
192
189
|
const s = rootElement.ownerDocument.createElement("style");
|
|
193
190
|
s.id = STYLE_TEXT_ID;
|
|
194
|
-
s.setAttribute("data-hash",
|
|
195
|
-
s.textContent =
|
|
191
|
+
s.setAttribute("data-hash", themeOverridesHash);
|
|
192
|
+
s.textContent = themeOverrides;
|
|
196
193
|
rootElement.appendChild(s);
|
|
197
194
|
} else {
|
|
198
195
|
const prevHash = existingStyle.getAttribute("data-hash") || "";
|
|
199
|
-
if (prevHash !==
|
|
200
|
-
existingStyle.setAttribute("data-hash",
|
|
201
|
-
existingStyle.textContent =
|
|
196
|
+
if (prevHash !== themeOverridesHash) {
|
|
197
|
+
existingStyle.setAttribute("data-hash", themeOverridesHash);
|
|
198
|
+
existingStyle.textContent = themeOverrides;
|
|
202
199
|
}
|
|
203
200
|
}
|
|
204
201
|
} else if (existingStyle) {
|
|
205
202
|
existingStyle.remove();
|
|
206
203
|
}
|
|
207
204
|
},
|
|
208
|
-
[
|
|
205
|
+
[themeOverrides, themeOverridesHash],
|
|
209
206
|
);
|
|
210
207
|
|
|
211
208
|
return (
|
|
@@ -214,7 +211,6 @@ export function withAiKitShell<P extends object>(
|
|
|
214
211
|
variation={variation}
|
|
215
212
|
overlayRootId="ai-kit-overlay-root"
|
|
216
213
|
stylesheets={stylesheets}
|
|
217
|
-
className={className}
|
|
218
214
|
rootElementId={
|
|
219
215
|
variation === "modal" && !showOpenButton
|
|
220
216
|
? "ai-kit-portal-root"
|
|
@@ -260,8 +256,7 @@ export function withAiKitShell<P extends object>(
|
|
|
260
256
|
);
|
|
261
257
|
};
|
|
262
258
|
|
|
263
|
-
Wrapped.displayName = `withAiKitShell(${
|
|
264
|
-
|
|
265
|
-
})`;
|
|
259
|
+
Wrapped.displayName = `withAiKitShell(${RootComponent.displayName ?? RootComponent.name ?? "Component"
|
|
260
|
+
})`;
|
|
266
261
|
return Wrapped;
|
|
267
262
|
}
|