@smart-cloud/ai-kit-ui 1.3.4 → 1.3.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart-cloud/ai-kit-ui",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
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.15",
23
- "@smart-cloud/ai-kit-core": "^1.3.3",
23
+ "@smart-cloud/ai-kit-core": "^1.3.5",
24
24
  "@smart-cloud/wpsuite-core": "^2.2.6",
25
25
  "@tabler/icons-react": "^3.36.1",
26
26
  "chroma-js": "^3.2.0",
@@ -26,7 +26,7 @@ import ReactMarkdown from "react-markdown";
26
26
  import rehypeRaw from "rehype-raw";
27
27
  import remarkGfm from "remark-gfm";
28
28
 
29
- import { IconSearch } from "@tabler/icons-react";
29
+ import { IconSearch, IconX } from "@tabler/icons-react";
30
30
  import { IconMicrophone, IconMicrophoneOff } from "@tabler/icons-react";
31
31
 
32
32
  import { AiFeatureBorder } from "../ai-feature/AiFeatureBorder";
@@ -69,6 +69,11 @@ const DocSearchBase: FC<Props> = (props) => {
69
69
  autoRun = true,
70
70
  context,
71
71
  title,
72
+ showOpenButton = false,
73
+ openButtonTitle,
74
+ showOpenButtonTitle = true,
75
+ openButtonIcon,
76
+ showOpenButtonIcon = true,
72
77
  searchButtonIcon,
73
78
  showSearchButtonTitle = true,
74
79
  showSearchButtonIcon = true,
@@ -82,17 +87,10 @@ const DocSearchBase: FC<Props> = (props) => {
82
87
  language,
83
88
  onClose,
84
89
  onClickDoc,
85
-
86
- // Open button props (from AiWorkerProps)
87
- showOpenButton = false,
88
- openButtonTitle,
89
- openButtonIcon,
90
- showOpenButtonTitle = true,
91
- showOpenButtonIcon = true,
92
90
  } = props;
93
91
 
94
- const [query, setQuery] = useState<string>("");
95
92
  const [featureOpen, setFeatureOpen] = useState<boolean>(!showOpenButton);
93
+ const [query, setQuery] = useState<string>("");
96
94
  const [recording, setRecording] = useState<boolean>(false);
97
95
  const [audioBlob, setAudioBlob] = useState<Blob | null>(null);
98
96
  const [audioLevel, setAudioLevel] = useState<number>(0);
@@ -142,10 +140,6 @@ const DocSearchBase: FC<Props> = (props) => {
142
140
  return I18n.get(title || "Search with AI-Kit");
143
141
  }, [language]);
144
142
 
145
- const getOpenButtonDefaultIcon = useCallback((className?: string) => {
146
- return <IconSearch className={className} size={18} />;
147
- }, []);
148
-
149
143
  const statusText = useMemo(() => {
150
144
  const e: AiKitStatusEvent | null = statusEvent;
151
145
  if (!e) return null;
@@ -159,10 +153,11 @@ const DocSearchBase: FC<Props> = (props) => {
159
153
 
160
154
  const canSearch = useMemo(() => {
161
155
  if (busy) return false;
156
+ if (!featureOpen) return false;
162
157
  // Can search if we have text OR audio
163
158
  const text = typeof inputText === "function" ? inputText() : inputText;
164
159
  return Boolean((text && text.trim().length > 0) || audioBlob);
165
- }, [inputText, busy, audioBlob]);
160
+ }, [inputText, busy, audioBlob, featureOpen]);
166
161
 
167
162
  const startRecording = useCallback(async () => {
168
163
  try {
@@ -428,7 +423,7 @@ const DocSearchBase: FC<Props> = (props) => {
428
423
  variation === "modal" ? Modal.Body : Group;
429
424
 
430
425
  useEffect(() => {
431
- if (variation !== "modal" || !featureOpen) {
426
+ if (variation !== "modal") {
432
427
  return;
433
428
  }
434
429
  document.body.style.overflow = "hidden";
@@ -454,13 +449,13 @@ const DocSearchBase: FC<Props> = (props) => {
454
449
  (openButtonIcon ? (
455
450
  <span dangerouslySetInnerHTML={{ __html: openButtonIcon }} />
456
451
  ) : (
457
- getOpenButtonDefaultIcon()
452
+ <IconSearch size={18} />
458
453
  ))
459
454
  }
460
455
  className={
461
456
  showOpenButtonTitle
462
- ? "doc-search-open-button"
463
- : "doc-search-open-button-no-title"
457
+ ? "ai-feature-open-button"
458
+ : "ai-feature-open-button-no-title"
464
459
  }
465
460
  variant={"filled"}
466
461
  disabled={featureOpen}
@@ -510,9 +505,37 @@ const DocSearchBase: FC<Props> = (props) => {
510
505
  <Paper shadow="sm" radius="md" p="md">
511
506
  <Stack gap="sm">
512
507
  {variation !== "modal" && (
513
- <Title order={4} style={{ margin: 0 }}>
514
- {I18n.get(defaultTitle)}
515
- </Title>
508
+ <Group justify="space-between">
509
+ <Title order={4} style={{ margin: 0 }}>
510
+ {I18n.get(defaultTitle)}
511
+ </Title>
512
+ {showOpenButton && (
513
+ <Button
514
+ variant="subtle"
515
+ color="gray"
516
+ size="xs"
517
+ onClick={close}
518
+ style={{
519
+ minWidth: 32,
520
+ padding: 0,
521
+ display: "flex",
522
+ alignItems: "center",
523
+ justifyContent: "center",
524
+ }}
525
+ aria-label={I18n.get("Close")}
526
+ >
527
+ <IconX
528
+ size={18}
529
+ style={{
530
+ color:
531
+ colorMode === "dark"
532
+ ? "var(--mantine-color-dark-1)"
533
+ : "var(--mantine-color-gray-7)",
534
+ }}
535
+ />
536
+ </Button>
537
+ )}
538
+ </Group>
516
539
  )}
517
540
 
518
541
  <Group gap="sm" align="flex-end" wrap="nowrap">