@smart-cloud/ai-kit-ui 1.3.8 → 1.3.9

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.8",
3
+ "version": "1.3.9",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -197,6 +197,23 @@ const DocSearchBase: FC<Props> = (props) => {
197
197
  return hasCategories || hasTags;
198
198
  }, [metadataOptions]);
199
199
 
200
+ const subcategories = useMemo(() => {
201
+ if (selectedCategories.length === 0 || !metadataOptions) {
202
+ return [];
203
+ }
204
+ return selectedCategories
205
+ .flatMap(
206
+ (cat) =>
207
+ metadataOptions.allowedCategories[
208
+ cat
209
+ ] || [],
210
+ )
211
+ .filter(
212
+ (subcat, index, self) =>
213
+ self.indexOf(subcat) === index,
214
+ )
215
+ }, [selectedCategories, metadataOptions]);
216
+
200
217
  const startRecording = useCallback(async () => {
201
218
  try {
202
219
  // Clear query input when starting audio recording
@@ -399,7 +416,7 @@ const DocSearchBase: FC<Props> = (props) => {
399
416
  "Reusing cached audio (no re-upload needed within",
400
417
  Math.round(
401
418
  (AUDIO_CACHE_TTL - (now - audioCacheRef.current!.uploadTimestamp)) /
402
- 1000,
419
+ 1000,
403
420
  ),
404
421
  "seconds)",
405
422
  );
@@ -421,8 +438,8 @@ const DocSearchBase: FC<Props> = (props) => {
421
438
  }),
422
439
  ...(enableUserFilters &&
423
440
  selectedSubcategories.length > 0 && {
424
- userSelectedSubcategories: selectedSubcategories,
425
- }),
441
+ userSelectedSubcategories: selectedSubcategories,
442
+ }),
426
443
  ...(enableUserFilters &&
427
444
  selectedTags.length > 0 && { userSelectedTags: selectedTags }),
428
445
  },
@@ -745,9 +762,9 @@ const DocSearchBase: FC<Props> = (props) => {
745
762
  style={
746
763
  recording
747
764
  ? {
748
- transform: `scale(${1 + audioLevel / 300})`,
749
- transition: "transform 0.1s ease-out",
750
- }
765
+ transform: `scale(${1 + audioLevel / 300})`,
766
+ transition: "transform 0.1s ease-out",
767
+ }
751
768
  : undefined
752
769
  }
753
770
  >
@@ -813,70 +830,60 @@ const DocSearchBase: FC<Props> = (props) => {
813
830
  {/* Main categories as checkboxes */}
814
831
  {Object.keys(metadataOptions.allowedCategories)
815
832
  .length > 0 && (
816
- <div>
817
- <Text size="sm" fw={500} mb="xs">
818
- {I18n.get("Categories")}
819
- </Text>
820
- <Group gap="md">
821
- {Object.keys(
822
- metadataOptions.allowedCategories,
823
- ).map((category) => (
824
- <Checkbox
825
- key={category}
826
- label={I18n.get(category)}
827
- checked={selectedCategories.includes(
828
- category,
829
- )}
830
- onChange={(e) => {
831
- if (e.currentTarget.checked) {
832
- setSelectedCategories([
833
- ...selectedCategories,
834
- category,
835
- ]);
836
- } else {
837
- setSelectedCategories(
838
- selectedCategories.filter(
839
- (c) => c !== category,
840
- ),
841
- );
842
- // Remove subcategories of unchecked category
843
- const subcatsToRemove =
844
- metadataOptions.allowedCategories[
833
+ <div>
834
+ <Text size="sm" fw={500} mb="xs">
835
+ {I18n.get("Categories")}
836
+ </Text>
837
+ <Group gap="md">
838
+ {Object.keys(
839
+ metadataOptions.allowedCategories,
840
+ ).map((category) => (
841
+ <Checkbox
842
+ key={category}
843
+ label={I18n.get(category)}
844
+ checked={selectedCategories.includes(
845
+ category,
846
+ )}
847
+ onChange={(e) => {
848
+ if (e.currentTarget.checked) {
849
+ setSelectedCategories([
850
+ ...selectedCategories,
851
+ category,
852
+ ]);
853
+ } else {
854
+ setSelectedCategories(
855
+ selectedCategories.filter(
856
+ (c) => c !== category,
857
+ ),
858
+ );
859
+ // Remove subcategories of unchecked category
860
+ const subcatsToRemove =
861
+ metadataOptions.allowedCategories[
845
862
  category
846
- ] || [];
847
- setSelectedSubcategories(
848
- selectedSubcategories.filter(
849
- (sc) =>
850
- !subcatsToRemove.includes(sc),
851
- ),
852
- );
853
- }
854
- }}
855
- disabled={busy || loadingMetadata}
856
- />
857
- ))}
858
- </Group>
859
- </div>
860
- )}
863
+ ] || [];
864
+ setSelectedSubcategories(
865
+ selectedSubcategories.filter(
866
+ (sc) =>
867
+ !subcatsToRemove.includes(sc),
868
+ ),
869
+ );
870
+ }
871
+ }}
872
+ disabled={busy || loadingMetadata}
873
+ />
874
+ ))}
875
+ </Group>
876
+ </div>
877
+ )}
861
878
 
862
879
  {/* Subcategories for selected categories */}
863
- {selectedCategories.length > 0 && (
880
+ {subcategories.length > 0 && (
864
881
  <div>
865
882
  <Text size="sm" fw={500} mb="xs">
866
883
  {I18n.get("Subcategories")}
867
884
  </Text>
868
885
  <Group gap="md">
869
- {selectedCategories
870
- .flatMap(
871
- (cat) =>
872
- metadataOptions.allowedCategories[
873
- cat
874
- ] || [],
875
- )
876
- .filter(
877
- (subcat, index, self) =>
878
- self.indexOf(subcat) === index,
879
- )
886
+ {subcategories
880
887
  .map((subcat) => (
881
888
  <Checkbox
882
889
  key={subcat}
@@ -1019,8 +1026,8 @@ const DocSearchBase: FC<Props> = (props) => {
1019
1026
  ) : null}
1020
1027
 
1021
1028
  {showSources &&
1022
- (result?.citations?.docs?.length ||
1023
- result?.citations?.chunks?.length) ? (
1029
+ (result?.citations?.docs?.length ||
1030
+ result?.citations?.chunks?.length) ? (
1024
1031
  <>
1025
1032
  <Divider />
1026
1033
  <Stack gap="sm" data-doc-search-sources>