@smart-cloud/ai-kit-ui 1.1.30 → 1.1.31

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.1.30",
3
+ "version": "1.1.31",
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.14",
23
- "@smart-cloud/ai-kit-core": "^1.1.14",
23
+ "@smart-cloud/ai-kit-core": "^1.1.16",
24
24
  "@smart-cloud/wpsuite-core": "^2.1.2",
25
25
  "@tabler/icons-react": "^3.36.1",
26
26
  "chroma-js": "^3.2.0",
@@ -333,6 +333,7 @@ const AiFeatureBase: FC<AiFeatureProps & AiKitShellInjectedProps> = (props) => {
333
333
  );
334
334
  }, [allowOverride]);
335
335
 
336
+ const [state, setState] = useState<string>();
336
337
  const [featureOpen, setFeatureOpen] = useState<boolean>(!showOpenButton);
337
338
  const [optionsOpen, setOptionsOpen] = useState<boolean>(false);
338
339
  const [backendConfigured, setBackendConfigured] = useState(false);
@@ -396,7 +397,7 @@ const AiFeatureBase: FC<AiFeatureProps & AiKitShellInjectedProps> = (props) => {
396
397
 
397
398
  const formatAiKitStatus = useCallback(
398
399
  (e: AiKitStatusEvent | null): string | null => {
399
- if (!e) return null;
400
+ if (!e || e.silent) return null;
400
401
 
401
402
  const step = e.step;
402
403
  const msg = I18n.get((e.message ?? "").trim());
@@ -420,11 +421,21 @@ const AiFeatureBase: FC<AiFeatureProps & AiKitShellInjectedProps> = (props) => {
420
421
  case "on-device:run":
421
422
  return msg || I18n.get("Generating...");
422
423
  case "backend:request":
423
- return msg || I18n.get("Sending request to backend...");
424
424
  case "backend:waiting":
425
- return msg || I18n.get("Waiting for backend response...");
426
425
  case "backend:response":
427
- return msg || I18n.get("Received backend response.");
426
+ switch (mode) {
427
+ case "rewrite":
428
+ return I18n.get("Rewriting text");
429
+ case "summarize":
430
+ return I18n.get("Summarizing");
431
+ case "proofread":
432
+ return I18n.get("Proofreading");
433
+ case "write":
434
+ case "generatePostMetadata":
435
+ case "generateImageMetadata":
436
+ default:
437
+ return I18n.get("Generating text");
438
+ }
428
439
  case "done":
429
440
  return msg || I18n.get("Done.");
430
441
  case "error":
@@ -433,7 +444,7 @@ const AiFeatureBase: FC<AiFeatureProps & AiKitShellInjectedProps> = (props) => {
433
444
  return msg || I18n.get("Working...");
434
445
  }
435
446
  },
436
- [language],
447
+ [language, mode],
437
448
  );
438
449
 
439
450
  const inputText = useMemo(() => {
@@ -463,7 +474,8 @@ const AiFeatureBase: FC<AiFeatureProps & AiKitShellInjectedProps> = (props) => {
463
474
  }, [inputText, mode, image, inputLanguage, outputLanguage]);
464
475
 
465
476
  const ai = useAiRun();
466
- const statusText = formatAiKitStatus(ai.statusEvent);
477
+ const statusText =
478
+ formatAiKitStatus(ai.statusEvent) ?? (state ? I18n.get(state) : null);
467
479
 
468
480
  const runGenerate = useCallback(
469
481
  async (modeOverride?: AiModePreference) => {
@@ -516,6 +528,7 @@ const AiFeatureBase: FC<AiFeatureProps & AiKitShellInjectedProps> = (props) => {
516
528
  context,
517
529
  modeOverride,
518
530
  onDeviceTimeoutOverride: onDeviceTimeout,
531
+ silent: true,
519
532
  },
520
533
  );
521
534
  const langCodes = res.result?.candidates
@@ -545,11 +558,13 @@ const AiFeatureBase: FC<AiFeatureProps & AiKitShellInjectedProps> = (props) => {
545
558
  const res = await ai.run(async ({ signal, onStatus }) => {
546
559
  let inputLang = inputLanguage ?? "auto";
547
560
  if (inputLang === "auto") {
561
+ setState("Detecting input language...");
548
562
  inputLang = await detectTopLanguage(text!.trim(), {
549
563
  signal,
550
564
  context,
551
565
  modeOverride,
552
566
  onDeviceTimeoutOverride: onDeviceTimeout,
567
+ silent: true,
553
568
  });
554
569
  setInputLanguage(inputLang);
555
570
  }
@@ -589,11 +604,13 @@ const AiFeatureBase: FC<AiFeatureProps & AiKitShellInjectedProps> = (props) => {
589
604
  ? outputLanguage
590
605
  : null) || readDefaultOutputLanguage();
591
606
  if (outputLanguage === "auto") {
607
+ setState("Detecting input language...");
592
608
  outLang = await detectTopLanguage(text!.trim(), {
593
609
  signal,
594
610
  context,
595
611
  modeOverride,
596
612
  onDeviceTimeoutOverride: onDeviceTimeout,
613
+ silent: true,
597
614
  });
598
615
  setOutputLanguage(outLang);
599
616
  }
@@ -637,12 +654,15 @@ const AiFeatureBase: FC<AiFeatureProps & AiKitShellInjectedProps> = (props) => {
637
654
  context,
638
655
  modeOverride,
639
656
  onDeviceTimeoutOverride: onDeviceTimeout,
657
+ silent: true,
640
658
  };
659
+ setState("Detecting input language...");
641
660
  const inLang = await detectTopLanguage(
642
661
  text!.trim() + "\n" + (instructions?.trim() || ""),
643
662
  langFeatureOptions,
644
663
  );
645
664
  if (inLang !== outLang && inLang !== "en") {
665
+ setState("Translating instructions...");
646
666
  args.prompt = (
647
667
  await translate(
648
668
  {
@@ -727,6 +747,7 @@ Follow these additional instructions: ${instructions}`
727
747
  ? outputLanguage
728
748
  : null) || readDefaultOutputLanguage();
729
749
  try {
750
+ setState("Translating result...");
730
751
  const parsed = (await ai.run(async ({ signal }) => {
731
752
  return await parsePostMetadataFromPromptResult(
732
753
  cleaned,
@@ -736,6 +757,7 @@ Follow these additional instructions: ${instructions}`
736
757
  context,
737
758
  modeOverride,
738
759
  onDeviceTimeoutOverride: onDeviceTimeout,
760
+ silent: true,
739
761
  },
740
762
  );
741
763
  })) as string | null;
@@ -811,6 +833,7 @@ Follow these additional instructions: ${instructions}`
811
833
 
812
834
  const cleaned = stripCodeFence(res).trim();
813
835
  try {
836
+ setState("Translating result...");
814
837
  const parsed = (await ai.run(async ({ signal }) => {
815
838
  return await parseImageMetadataFromPromptResult(
816
839
  cleaned,
@@ -820,6 +843,7 @@ Follow these additional instructions: ${instructions}`
820
843
  context,
821
844
  modeOverride,
822
845
  onDeviceTimeoutOverride: onDeviceTimeout,
846
+ silent: true,
823
847
  },
824
848
  );
825
849
  })) as string | null;
@@ -840,6 +864,7 @@ Follow these additional instructions: ${instructions}`
840
864
  : I18n.get("An unknown error occurred."),
841
865
  );
842
866
  }
867
+ setState(undefined);
843
868
  },
844
869
  [
845
870
  language,