@smart-cloud/ai-kit-ui 1.5.14 → 1.5.15

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.
Files changed (54) hide show
  1. package/dist/LocaleDirectionProvider.d.ts +5 -0
  2. package/dist/index.cjs +9 -9
  3. package/dist/index.js +9 -9
  4. package/dist/locale.d.ts +13 -0
  5. package/package.json +35 -19
  6. package/eslint.config.js +0 -18
  7. package/src/ShadowBoundary.tsx +0 -229
  8. package/src/ai-chatbot/AiChatbot.tsx +0 -2325
  9. package/src/ai-chatbot/attachmentStorage.ts +0 -238
  10. package/src/ai-chatbot/index.tsx +0 -1
  11. package/src/ai-feature/AiFeature.tsx +0 -2334
  12. package/src/ai-feature/AiFeatureBorder.tsx +0 -22
  13. package/src/ai-feature/ProofreadDiff.tsx +0 -118
  14. package/src/ai-feature/index.tsx +0 -2
  15. package/src/ai-feature/utils.tsx +0 -20
  16. package/src/doc-search/DocSearch.tsx +0 -1313
  17. package/src/doc-search/index.tsx +0 -1
  18. package/src/doc-search/initialFilters.ts +0 -10
  19. package/src/errorHandling.ts +0 -305
  20. package/src/i18n/ar.ts +0 -254
  21. package/src/i18n/de.ts +0 -257
  22. package/src/i18n/en.ts +0 -269
  23. package/src/i18n/es.ts +0 -257
  24. package/src/i18n/fr.ts +0 -258
  25. package/src/i18n/he.ts +0 -250
  26. package/src/i18n/hi.ts +0 -256
  27. package/src/i18n/hu.ts +0 -269
  28. package/src/i18n/id.ts +0 -256
  29. package/src/i18n/index.ts +0 -47
  30. package/src/i18n/it.ts +0 -259
  31. package/src/i18n/ja.ts +0 -256
  32. package/src/i18n/ko.ts +0 -254
  33. package/src/i18n/nb.ts +0 -254
  34. package/src/i18n/nl.ts +0 -255
  35. package/src/i18n/pl.ts +0 -258
  36. package/src/i18n/pt.ts +0 -254
  37. package/src/i18n/ru.ts +0 -254
  38. package/src/i18n/sv.ts +0 -253
  39. package/src/i18n/th.ts +0 -252
  40. package/src/i18n/tr.ts +0 -256
  41. package/src/i18n/ua.ts +0 -257
  42. package/src/i18n/zh.ts +0 -247
  43. package/src/index.tsx +0 -7
  44. package/src/poweredBy.tsx +0 -39
  45. package/src/styles/ai-kit-ui.css +0 -1006
  46. package/src/useAiRun.ts +0 -182
  47. package/src/withAiKitShell.tsx +0 -363
  48. package/tests/ai-disclosures.test.ts +0 -126
  49. package/tests/doc-search-initial-filters.test.ts +0 -20
  50. package/tests/error-handling.test.ts +0 -140
  51. package/tsconfig.json +0 -32
  52. package/tsconfig.node.json +0 -13
  53. package/tsconfig.types.json +0 -13
  54. package/tsup.config.ts +0 -22
package/src/useAiRun.ts DELETED
@@ -1,182 +0,0 @@
1
- import {
2
- AiKitLanguageCode,
3
- AiKitPlugin,
4
- AiKitSettings,
5
- getAiKitPlugin,
6
- getStoreSelect,
7
- type AiKitConfig,
8
- type AiKitStatusEvent,
9
- } from "@smart-cloud/ai-kit-core";
10
- import { getWpSuite } from "@smart-cloud/wpsuite-core";
11
- import { I18n } from "aws-amplify/utils";
12
- import { useCallback, useRef, useState } from "react";
13
- import {
14
- AiRunError,
15
- type AiRunErrorDetails,
16
- clearAiRunErrorFeedback,
17
- createAiRunErrorFeedback,
18
- isAiRunAbort,
19
- } from "./errorHandling";
20
-
21
- export type AiRunState<T> = {
22
- busy: boolean;
23
- error: string | null;
24
- errorDetails: AiRunErrorDetails | null;
25
- statusEvent: AiKitStatusEvent | null;
26
- result: T | null;
27
- isCancelled: boolean;
28
- /** Last known execution source (best-effort). */
29
- lastSource: "on-device" | "backend" | null;
30
- };
31
-
32
- export type AiFeatureFunction<T> = (args: {
33
- signal: AbortSignal;
34
- onStatus: (e: AiKitStatusEvent) => void;
35
- }) => Promise<T>;
36
-
37
- export type UseAiRunResult<T> = AiRunState<T> & {
38
- run: (func: AiFeatureFunction<T>) => Promise<T | null>;
39
- cancel: () => void;
40
- reset: () => void;
41
- /** Current AbortSignal, if a run is in-flight. */
42
- signal: AbortSignal | null;
43
- };
44
-
45
- /**
46
- * Returns true if backend routing is configured in the current AiKit settings.
47
- *
48
- * This is intentionally conservative: it only checks *configuration*, not reachability.
49
- */
50
- export async function isBackendConfigured(): Promise<boolean> {
51
- const store = await getAiKitPlugin().features.store;
52
- if (!store) {
53
- return false;
54
- }
55
- const s: AiKitConfig = getStoreSelect(store).getConfig() ?? {};
56
- if (s.backendTransport === "gatey") {
57
- return Boolean(s.backendApiName);
58
- }
59
- if (s.backendTransport === "fetch") {
60
- return Boolean(s.backendBaseUrl);
61
- }
62
- // Unknown/undefined transport: treat as not configured.
63
- return false;
64
- }
65
-
66
- export function readDefaultOutputLanguage(): AiKitLanguageCode {
67
- const aiKit = getWpSuite()?.plugins?.aiKit as AiKitPlugin | undefined;
68
- return (
69
- ((aiKit?.settings ?? {}) as AiKitSettings).defaultOutputLanguage ?? "en"
70
- );
71
- }
72
-
73
- /**
74
- * Removes a single surrounding Markdown code fence.
75
- *
76
- * Handles common model outputs like:
77
- * ```json
78
- * {"a":1}
79
- * ```
80
- */
81
- export function stripCodeFence(text: string): string {
82
- const fence = /^\s*```(?:json)?\s*([\s\S]*?)\s*```\s*$/i;
83
- const m = text.match(fence);
84
- return m ? m[1] : text;
85
- }
86
-
87
- export function useAiRun<T>(): UseAiRunResult<T> {
88
- const ctrlRef = useRef<AbortController | null>(null);
89
- const lastSourceRef = useRef<"on-device" | "backend" | null>(null);
90
-
91
- const [busy, setBusy] = useState(false);
92
- const [errorFeedback, setErrorFeedback] = useState(clearAiRunErrorFeedback);
93
- const [statusEvent, setStatusEvent] = useState<AiKitStatusEvent | null>(null);
94
- const [result, setResult] = useState<T | null>(null);
95
- const [isCancelled, setIsCancelled] = useState(false);
96
- const [lastSource, setLastSource] = useState<"on-device" | "backend" | null>(
97
- null,
98
- );
99
-
100
- const cancel = useCallback(() => {
101
- ctrlRef.current?.abort();
102
- }, []);
103
-
104
- const reset = useCallback(() => {
105
- ctrlRef.current?.abort();
106
- ctrlRef.current = null;
107
- setBusy(false);
108
- setErrorFeedback(clearAiRunErrorFeedback());
109
- setStatusEvent(null);
110
- setResult(null);
111
- setIsCancelled(false);
112
- lastSourceRef.current = null;
113
- setLastSource(null);
114
- }, []);
115
-
116
- const run = useCallback(
117
- async (func: AiFeatureFunction<T>): Promise<T | null> => {
118
- // Cancel any ongoing run
119
- ctrlRef.current?.abort();
120
-
121
- const ctrl = new AbortController();
122
- ctrlRef.current = ctrl;
123
-
124
- setBusy(true);
125
- setErrorFeedback(clearAiRunErrorFeedback());
126
- setStatusEvent(null);
127
- setResult(null);
128
- setIsCancelled(false);
129
- lastSourceRef.current = null;
130
- setLastSource(null);
131
-
132
- try {
133
- const value = await func({
134
- signal: ctrl.signal,
135
- onStatus: (e) => {
136
- setStatusEvent(e);
137
- if (e.source === "on-device" || e.source === "backend") {
138
- lastSourceRef.current = e.source;
139
- setLastSource(e.source);
140
- }
141
- },
142
- });
143
- setResult(value);
144
- return value;
145
- } catch (err) {
146
- if (ctrl.signal.aborted || isAiRunAbort(err)) {
147
- setIsCancelled(true);
148
- setErrorFeedback(clearAiRunErrorFeedback());
149
- return null;
150
- }
151
- const feedback = createAiRunErrorFeedback(err, (message) =>
152
- I18n.get(message),
153
- );
154
- setErrorFeedback(feedback);
155
- throw new AiRunError(feedback.details!, feedback.message!, {
156
- cause: err,
157
- });
158
- } finally {
159
- setBusy(false);
160
- setStatusEvent(null);
161
- }
162
- },
163
- [],
164
- );
165
-
166
- // NOTE: do not memoize; ctrlRef changes don't trigger rerender.
167
- const signal = ctrlRef.current?.signal ?? null;
168
-
169
- return {
170
- busy,
171
- error: errorFeedback.message,
172
- errorDetails: errorFeedback.details,
173
- statusEvent,
174
- result,
175
- isCancelled,
176
- lastSource,
177
- run,
178
- cancel,
179
- reset,
180
- signal,
181
- };
182
- }
@@ -1,363 +0,0 @@
1
- import { generateColors } from "@mantine/colors-generator";
2
- import {
3
- colorsTuple,
4
- createTheme,
5
- DEFAULT_THEME,
6
- DirectionProvider,
7
- MantineColorsTuple,
8
- MantineProvider,
9
- } from "@mantine/core";
10
- import {
11
- AiWorkerProps,
12
- CustomTranslations,
13
- getStoreSelect,
14
- } from "@smart-cloud/ai-kit-core";
15
- import { useSelect } from "@wordpress/data";
16
- import { I18n } from "aws-amplify/utils";
17
- import { type ComponentType, useEffect, useMemo, useState } from "react";
18
- import { ShadowBoundary } from "./ShadowBoundary";
19
-
20
- export type AiKitShellInjectedProps = {
21
- language?: string;
22
- rootElement: HTMLElement;
23
- /** Global portal target for an opened modal; its trigger stays local. */
24
- modalRootElement?: HTMLElement;
25
- };
26
-
27
- type AiKitShellOptions = Partial<AiWorkerProps> & {
28
- /** Used only by intentionally floating components such as the chatbot. */
29
- overlayWholeComponent?: boolean;
30
- };
31
-
32
- const hashStringDjb2 = (str: string): string => {
33
- let hash = 5381;
34
- for (let i = 0; i < str.length; i++) {
35
- hash = ((hash << 5) + hash) ^ str.charCodeAt(i);
36
- }
37
- // unsigned + base36
38
- return (hash >>> 0).toString(36);
39
- };
40
-
41
- const sanitizeThemeOverrides = (input: string): string =>
42
- input
43
- .replace(/<\/?(?:style|script)\b[^>]*>/gi, "")
44
- .replace(/@import\s+['"]?javascript:[^;]+;?/gi, "")
45
- .replace(/url\(\s*(['"]?)javascript:[^)]+\)/gi, "")
46
- .replace(/\bexpression\s*\([^)]*\)/gi, "");
47
-
48
- const STYLE_TEXT_ID = "ai-kit-style-text";
49
-
50
- export function withAiKitShell<P extends object>(
51
- RootComponent: ComponentType<P & AiKitShellInjectedProps>,
52
- propOverrides?: AiKitShellOptions,
53
- ) {
54
- const Wrapped: React.FC<P & Partial<AiWorkerProps>> = (props) => {
55
- // Duck-typing merge: supports both explicit shell props or defaults.
56
- const {
57
- store,
58
- variation,
59
- colors,
60
- colorMode,
61
- primaryColor,
62
- primaryShade,
63
- themeOverrides,
64
- language,
65
- direction,
66
- } = { ...props, ...propOverrides } as AiWorkerProps & P;
67
-
68
- const [host, setHost] = useState<HTMLElement | null>(null);
69
- const [modalRootElement, setModalRootElement] =
70
- useState<HTMLDivElement | null>(null);
71
- const overlayWholeComponent = Boolean(propOverrides?.overlayWholeComponent);
72
- const languageInStore: string | undefined | null = useSelect(() =>
73
- getStoreSelect(store).getLanguage(),
74
- );
75
- const directionInStore: "ltr" | "rtl" | "auto" | undefined | null =
76
- useSelect(() => getStoreSelect(store).getDirection());
77
- const customTranslations: CustomTranslations | undefined | null = useSelect(
78
- () => getStoreSelect(store).getCustomTranslations(),
79
- );
80
- const [languageOverride] = useState<string>(
81
- new URLSearchParams(window.location.search).get("language") ?? "",
82
- );
83
- const [directionOverride] = useState<string>(
84
- new URLSearchParams(window.location.search).get("direction") ?? "",
85
- );
86
- const currentLanguage = useMemo(() => {
87
- I18n.putVocabularies(customTranslations || {});
88
- const lang = languageInStore || languageOverride || language;
89
- if (!lang || lang === "system") {
90
- I18n.setLanguage("");
91
- return undefined;
92
- }
93
- I18n.setLanguage(lang);
94
- return lang;
95
- }, [language, languageOverride, languageInStore, customTranslations]);
96
-
97
- const currentDirection = useMemo(() => {
98
- const dir = directionInStore || directionOverride || direction;
99
- if (!dir || dir === "auto") {
100
- return currentLanguage === "ar" || currentLanguage === "he"
101
- ? "rtl"
102
- : "ltr";
103
- }
104
- return dir as "ltr" | "rtl";
105
- }, [currentLanguage, direction, directionInStore, directionOverride]);
106
-
107
- const stylesheets = useMemo(
108
- () =>
109
- [
110
- (
111
- WpSuite as never as {
112
- constants: { aiKit: { mantineCssHref: string } };
113
- }
114
- )?.constants?.aiKit?.mantineCssHref,
115
- (
116
- WpSuite as never as {
117
- constants: { aiKit: { aiKitUiCssHref: string } };
118
- }
119
- )?.constants?.aiKit?.aiKitUiCssHref,
120
- (
121
- WpSuite as never as {
122
- constants: { aiKit: { wpsuiteThemeCssHref?: string } };
123
- }
124
- )?.constants?.aiKit?.wpsuiteThemeCssHref,
125
- ].filter(
126
- (href): href is string => typeof href === "string" && href.length > 0,
127
- ),
128
- [WpSuite],
129
- );
130
-
131
- let customColors: Record<string, MantineColorsTuple> | undefined;
132
- if (colors) {
133
- customColors = {};
134
- Object.keys(colors).forEach((c) => {
135
- try {
136
- customColors![c] = generateColors(colors[c]);
137
- } catch {
138
- customColors![c] = colorsTuple(colors[c]);
139
- }
140
- });
141
- }
142
-
143
- const theme = createTheme({
144
- respectReducedMotion: true,
145
- ...(customColors && { colors: customColors }),
146
- ...(primaryColor &&
147
- [
148
- ...Object.keys(DEFAULT_THEME.colors),
149
- ...Object.keys(customColors || {}),
150
- ].includes(primaryColor) && { primaryColor }),
151
- ...(primaryShade &&
152
- Object.keys(primaryShade).length > 0 && {
153
- primaryShade: {
154
- light:
155
- primaryShade.light ??
156
- (typeof DEFAULT_THEME.primaryShade === "object"
157
- ? DEFAULT_THEME.primaryShade.light
158
- : (DEFAULT_THEME.primaryShade ?? 6)),
159
- dark:
160
- primaryShade.dark ??
161
- (typeof DEFAULT_THEME.primaryShade === "object"
162
- ? DEFAULT_THEME.primaryShade.dark
163
- : (DEFAULT_THEME.primaryShade ?? 6)),
164
- },
165
- }),
166
- components: {
167
- Button: {
168
- styles: { root: { borderRadius: "inherit" } },
169
- },
170
- Tooltip: {
171
- defaultProps: {
172
- withinPortal: false,
173
- zIndex: 100002,
174
- },
175
- },
176
- Modal: {
177
- defaultProps: {
178
- withinPortal: false,
179
- zIndex: 100002,
180
- },
181
- },
182
- Select: {
183
- defaultProps: {
184
- comboboxProps: {
185
- withinPortal: false,
186
- floatingStrategy: "fixed",
187
- positionDependencies: [],
188
- position: "bottom",
189
- middlewares: {
190
- flip: false,
191
- shift: {
192
- padding: 10,
193
- boundary: "clippingAncestors",
194
- },
195
- },
196
- },
197
- },
198
- },
199
- MultiSelect: {
200
- defaultProps: {
201
- comboboxProps: {
202
- withinPortal: false,
203
- floatingStrategy: "fixed",
204
- positionDependencies: [],
205
- position: "bottom",
206
- middlewares: {
207
- flip: false,
208
- shift: {
209
- padding: 10,
210
- boundary: "clippingAncestors",
211
- },
212
- },
213
- },
214
- },
215
- },
216
- TagsInput: {
217
- defaultProps: {
218
- comboboxProps: {
219
- withinPortal: false,
220
- floatingStrategy: "fixed",
221
- positionDependencies: [],
222
- position: "bottom",
223
- middlewares: {
224
- flip: false,
225
- shift: {
226
- padding: 10,
227
- boundary: "clippingAncestors",
228
- },
229
- },
230
- },
231
- },
232
- },
233
- },
234
- });
235
-
236
- const themeOverridesHash = useMemo(() => {
237
- return themeOverrides ? hashStringDjb2(themeOverrides) : "";
238
- }, [themeOverrides]);
239
-
240
- useEffect(() => {
241
- if (!host) {
242
- return;
243
- }
244
-
245
- const existingStyle = host.shadowRoot!.getElementById(
246
- STYLE_TEXT_ID,
247
- ) as HTMLStyleElement | null;
248
-
249
- if (themeOverrides) {
250
- if (!existingStyle) {
251
- const s = host.shadowRoot!.ownerDocument.createElement("style");
252
- s.id = STYLE_TEXT_ID;
253
- s.setAttribute("data-hash", themeOverridesHash);
254
- s.textContent = sanitizeThemeOverrides(themeOverrides);
255
- host.shadowRoot!.appendChild(s);
256
- } else {
257
- const prevHash = existingStyle.getAttribute("data-hash") || "";
258
- if (prevHash !== themeOverridesHash) {
259
- existingStyle.textContent = sanitizeThemeOverrides(themeOverrides);
260
- }
261
- }
262
- } else if (existingStyle) {
263
- existingStyle.remove();
264
- }
265
- }, [host, themeOverrides, themeOverridesHash]);
266
-
267
- const usesSeparateModalPortal =
268
- variation === "modal" && !overlayWholeComponent;
269
-
270
- return (
271
- <>
272
- {usesSeparateModalPortal ? (
273
- <ShadowBoundary
274
- mode="overlay"
275
- overlayRootId="ai-kit-overlay-root"
276
- stylesheets={stylesheets}
277
- setHost={() => undefined}
278
- setRootElement={setModalRootElement}
279
- rootElementId="ai-kit-portal-root"
280
- >
281
- {() => null}
282
- </ShadowBoundary>
283
- ) : null}
284
- <ShadowBoundary
285
- // Header controls must remain in their authored block. Only the
286
- // opened dialog belongs in the global, viewport-sized overlay.
287
- mode={overlayWholeComponent && variation === "modal" ? "overlay" : "local"}
288
- variation={variation}
289
- overlayRootId="ai-kit-overlay-root"
290
- stylesheets={stylesheets}
291
- setHost={setHost}
292
- rootElementId={
293
- overlayWholeComponent && variation === "modal"
294
- ? "ai-kit-portal-root"
295
- : "ai-kit-inline-root"
296
- }
297
- >
298
- {({ rootElement }) => {
299
- rootElement.setAttribute(
300
- "data-ai-kit-variation",
301
- variation || "default",
302
- );
303
- rootElement.setAttribute("dir", currentDirection);
304
- if (currentLanguage) {
305
- rootElement.setAttribute("lang", currentLanguage);
306
- }
307
-
308
- const resolved =
309
- colorMode === "auto"
310
- ? window.matchMedia?.("(prefers-color-scheme: dark)")?.matches
311
- ? "dark"
312
- : "light"
313
- : colorMode;
314
-
315
- // Modal content is portalled into a different shadow tree. Mantine
316
- // color-scheme attributes do not cross that boundary, so copy the
317
- // contextual attributes that the global overlay needs explicitly.
318
- if (usesSeparateModalPortal && modalRootElement) {
319
- modalRootElement.setAttribute("data-ai-kit-variation", "modal");
320
- modalRootElement.setAttribute(
321
- "data-mantine-color-scheme",
322
- resolved ?? "light",
323
- );
324
- modalRootElement.setAttribute("dir", currentDirection);
325
- if (currentLanguage) {
326
- modalRootElement.setAttribute("lang", currentLanguage);
327
- } else {
328
- modalRootElement.removeAttribute("lang");
329
- }
330
- }
331
-
332
- return (
333
- <DirectionProvider initialDirection={currentDirection}>
334
- <MantineProvider
335
- forceColorScheme={resolved}
336
- theme={theme}
337
- getRootElement={() => rootElement as unknown as HTMLElement}
338
- >
339
- <RootComponent
340
- {...props}
341
- colorMode={resolved}
342
- language={currentLanguage}
343
- rootElement={rootElement}
344
- modalRootElement={
345
- usesSeparateModalPortal
346
- ? modalRootElement ?? rootElement
347
- : rootElement
348
- }
349
- />
350
- </MantineProvider>
351
- </DirectionProvider>
352
- );
353
- }}
354
- </ShadowBoundary>
355
- </>
356
- );
357
- };
358
-
359
- Wrapped.displayName = `withAiKitShell(${
360
- RootComponent.displayName ?? RootComponent.name ?? "Component"
361
- })`;
362
- return Wrapped;
363
- }
@@ -1,126 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import fs from "node:fs/promises";
3
- import path from "node:path";
4
- import test from "node:test";
5
- import { fileURLToPath } from "node:url";
6
- import ts from "typescript";
7
-
8
- const CHATBOT_DISCLOSURE =
9
- "Answers from {name} are generated by AI and may contain mistakes. Check important information.";
10
- const DOC_SEARCH_DISCLOSURE =
11
- "This summary was generated by AI and may contain mistakes. Check important information.";
12
- const MODEL_CAPABILITY_ERROR =
13
- "The configured AI model does not support image attachments. Contact the site administrator.";
14
-
15
- const importTypeScript = async (fileUrl: URL) => {
16
- const source = await fs.readFile(fileUrl, "utf8");
17
- const compiled = ts.transpileModule(source, {
18
- compilerOptions: {
19
- module: ts.ModuleKind.ESNext,
20
- target: ts.ScriptTarget.ES2022,
21
- },
22
- }).outputText;
23
- return import(
24
- `data:text/javascript;base64,${Buffer.from(compiled).toString("base64")}`
25
- );
26
- };
27
-
28
- test("formats every chatbot name placeholder", async () => {
29
- const disclosures = await importTypeScript(
30
- new URL("../../core/src/ai-disclosures.ts", import.meta.url),
31
- );
32
-
33
- assert.equal(disclosures.DEFAULT_CHATBOT_AI_DISCLOSURE, CHATBOT_DISCLOSURE);
34
- assert.equal(
35
- disclosures.formatAiDisclosure("{name}: ask {name}", "Support Bot"),
36
- "Support Bot: ask Support Bot",
37
- );
38
- });
39
-
40
- test("all supported languages contain alphabetized AI disclosures", async () => {
41
- const directory = fileURLToPath(new URL("../src/i18n", import.meta.url));
42
- const files = (await fs.readdir(directory))
43
- .filter((file) => file.endsWith(".ts") && file !== "index.ts")
44
- .sort();
45
-
46
- assert.equal(files.length, 22);
47
-
48
- for (const file of files) {
49
- const module = await importTypeScript(
50
- new URL(`../src/i18n/${file}`, import.meta.url),
51
- );
52
- const dictionary = Object.values(module).find(
53
- (value) => typeof value === "object" && value !== null,
54
- ) as Record<string, string> | undefined;
55
-
56
- assert.ok(dictionary, `${file} must export a dictionary`);
57
- assert.ok(
58
- dictionary[CHATBOT_DISCLOSURE]?.includes("{name}"),
59
- `${file} must preserve the chatbot name placeholder`,
60
- );
61
- assert.ok(
62
- dictionary[DOC_SEARCH_DISCLOSURE]?.trim(),
63
- `${file} must translate the DocSearch disclosure`,
64
- );
65
- assert.ok(
66
- dictionary[MODEL_CAPABILITY_ERROR]?.trim(),
67
- `${file} must translate the model capability error`,
68
- );
69
-
70
- const keys = Object.keys(dictionary);
71
- assert.equal(
72
- keys.indexOf(CHATBOT_DISCLOSURE),
73
- keys.indexOf("An unknown error occurred.") + 1,
74
- `${file} must keep the chatbot disclosure alphabetized`,
75
- );
76
- assert.equal(
77
- keys.indexOf(DOC_SEARCH_DISCLOSURE),
78
- keys.indexOf("Title") - 1,
79
- `${file} must keep the DocSearch disclosure alphabetized`,
80
- );
81
- assert.equal(
82
- keys.indexOf(MODEL_CAPABILITY_ERROR),
83
- keys.indexOf("The caption for the image.") + 1,
84
- `${file} must keep the model capability error alphabetized`,
85
- );
86
- }
87
- });
88
-
89
- test("renders the chatbot disclosure beside status and outside the composer box", async () => {
90
- const component = await fs.readFile(
91
- new URL("../src/ai-chatbot/AiChatbot.tsx", import.meta.url),
92
- "utf8",
93
- );
94
- const statusIndex = component.indexOf('className="ai-status-line"');
95
- const disclosureIndex = component.indexOf(
96
- 'className="ai-generated-content-disclosure ai-chatbot-generated-content-disclosure"',
97
- );
98
- const composerIndex = component.indexOf(
99
- '<Stack className="ai-box ai-box-open">',
100
- );
101
-
102
- assert.ok(statusIndex >= 0, "chatbot status line must be rendered");
103
- assert.ok(disclosureIndex > statusIndex, "disclosure must follow status");
104
- assert.ok(
105
- composerIndex > disclosureIndex,
106
- "disclosure must be outside and above the composer box",
107
- );
108
- });
109
-
110
- test("keeps chatbot image attachments explicitly opt-in", async () => {
111
- const component = await fs.readFile(
112
- new URL("../src/ai-chatbot/AiChatbot.tsx", import.meta.url),
113
- "utf8",
114
- );
115
-
116
- assert.match(component, /const DEFAULT_MAX_IMAGES = 0;/);
117
- assert.match(
118
- component,
119
- /const imageAttachmentsEnabled = resolvedMaxImages > 0;/,
120
- );
121
- assert.match(
122
- component,
123
- /const selectedImages = imageAttachmentsEnabled[\s\S]*?composerImagesRef\.current[\s\S]*?: \[\];/,
124
- );
125
- assert.match(component, /\{imageAttachmentsEnabled && \(/);
126
- });
@@ -1,20 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import test from "node:test";
3
-
4
- import { normalizeInitialFilterValues } from "../src/doc-search/initialFilters.ts";
5
-
6
- test("normalizes, deduplicates, and preserves initial DocSearch filters", () => {
7
- assert.deepEqual(
8
- normalizeInitialFilterValues([
9
- " Solutions ",
10
- "",
11
- "Solution Guide",
12
- "Solutions",
13
- ]),
14
- ["Solutions", "Solution Guide"],
15
- );
16
- });
17
-
18
- test("uses an empty selection when initial DocSearch filters are omitted", () => {
19
- assert.deepEqual(normalizeInitialFilterValues(undefined), []);
20
- });