@smart-cloud/ai-kit-ui 1.4.0 → 1.4.2
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.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -9
- package/package.json +5 -2
- package/src/ai-feature/AiFeature.tsx +47 -8
- package/tsup.config.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smart-cloud/ai-kit-ui",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -20,17 +20,20 @@
|
|
|
20
20
|
"@emotion/cache": "^11.14.0",
|
|
21
21
|
"@emotion/react": "^11.14.0",
|
|
22
22
|
"@mantine/colors-generator": "^8.3.16",
|
|
23
|
-
"@smart-cloud/ai-kit-core": "^1.4.
|
|
23
|
+
"@smart-cloud/ai-kit-core": "^1.4.4",
|
|
24
24
|
"@smart-cloud/wpsuite-core": "^2.2.10",
|
|
25
25
|
"@tabler/icons-react": "^3.40.0",
|
|
26
26
|
"chroma-js": "^3.2.0",
|
|
27
27
|
"react-markdown": "^10.1.0",
|
|
28
|
+
"rehype-parse": "^9.0.1",
|
|
28
29
|
"rehype-raw": "^7.0.0",
|
|
30
|
+
"rehype-remark": "^10.0.0",
|
|
29
31
|
"rehype-sanitize": "^6.0.0",
|
|
30
32
|
"rehype-stringify": "^10.0.1",
|
|
31
33
|
"remark-gfm": "^4.0.1",
|
|
32
34
|
"remark-parse": "^11.0.0",
|
|
33
35
|
"remark-rehype": "^11.1.2",
|
|
36
|
+
"remark-stringify": "^11.0.0",
|
|
34
37
|
"unified": "^11.0.5"
|
|
35
38
|
},
|
|
36
39
|
"peerDependencies": {
|
|
@@ -472,7 +472,31 @@ const AiFeatureBase: FC<AiFeatureProps & AiKitShellInjectedProps> = (props) => {
|
|
|
472
472
|
}, [text, defaults]);
|
|
473
473
|
|
|
474
474
|
const canGenerate = useMemo(() => {
|
|
475
|
-
|
|
475
|
+
// If inputText is a function (async or sync getText), we can't determine
|
|
476
|
+
// if it has content without calling it. Assume it's valid if provided.
|
|
477
|
+
const input = inputText;
|
|
478
|
+
if (typeof input === "function") {
|
|
479
|
+
switch (mode) {
|
|
480
|
+
case "generateImageMetadata":
|
|
481
|
+
return Boolean(image);
|
|
482
|
+
case "translate":
|
|
483
|
+
// For translate, we need outputLanguage check, but can't check text without calling getText
|
|
484
|
+
return Boolean(
|
|
485
|
+
!outputLanguage || detectedLanguage !== outputLanguage,
|
|
486
|
+
);
|
|
487
|
+
case "summarize":
|
|
488
|
+
case "proofread":
|
|
489
|
+
case "rewrite":
|
|
490
|
+
case "write":
|
|
491
|
+
case "generatePostMetadata":
|
|
492
|
+
return true; // Assume getText will provide valid content
|
|
493
|
+
default:
|
|
494
|
+
return false;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// If inputText is a string, check it directly
|
|
499
|
+
const text = input as string | undefined;
|
|
476
500
|
switch (mode) {
|
|
477
501
|
case "generateImageMetadata":
|
|
478
502
|
return Boolean(image);
|
|
@@ -507,8 +531,11 @@ const AiFeatureBase: FC<AiFeatureProps & AiKitShellInjectedProps> = (props) => {
|
|
|
507
531
|
setError(null);
|
|
508
532
|
setGenerated(null);
|
|
509
533
|
|
|
534
|
+
const input = await inputText;
|
|
510
535
|
try {
|
|
511
|
-
|
|
536
|
+
// Support both sync and async getText functions
|
|
537
|
+
const text =
|
|
538
|
+
typeof input === "function" ? await Promise.resolve(input()) : input;
|
|
512
539
|
switch (mode) {
|
|
513
540
|
case "summarize": {
|
|
514
541
|
const res = await ai.run(async ({ signal, onStatus }) => {
|
|
@@ -524,13 +551,17 @@ const AiFeatureBase: FC<AiFeatureProps & AiKitShellInjectedProps> = (props) => {
|
|
|
524
551
|
type: type as SummarizerType,
|
|
525
552
|
outputLanguage: outLang as SummarizeArgs["outputLanguage"],
|
|
526
553
|
};
|
|
527
|
-
|
|
554
|
+
|
|
555
|
+
const featureOptions: FeatureOptions = {
|
|
528
556
|
signal,
|
|
529
557
|
onStatus,
|
|
530
558
|
context,
|
|
531
559
|
modeOverride,
|
|
532
560
|
onDeviceTimeoutOverride: onDeviceTimeout,
|
|
533
|
-
}
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
// Normal single-pass summarization
|
|
564
|
+
const out = await summarize(args, featureOptions);
|
|
534
565
|
return out.result;
|
|
535
566
|
});
|
|
536
567
|
setGenerated((res as never) ?? "");
|
|
@@ -614,13 +645,17 @@ const AiFeatureBase: FC<AiFeatureProps & AiKitShellInjectedProps> = (props) => {
|
|
|
614
645
|
sourceLanguage: inputLang!,
|
|
615
646
|
targetLanguage: outLang,
|
|
616
647
|
};
|
|
617
|
-
|
|
648
|
+
|
|
649
|
+
const featureOptions: FeatureOptions = {
|
|
618
650
|
signal,
|
|
619
651
|
onStatus,
|
|
620
652
|
context,
|
|
621
653
|
modeOverride,
|
|
622
654
|
onDeviceTimeoutOverride: onDeviceTimeout,
|
|
623
|
-
}
|
|
655
|
+
};
|
|
656
|
+
|
|
657
|
+
// Normal single-pass translation
|
|
658
|
+
const out = await translate(args, featureOptions);
|
|
624
659
|
return out.result;
|
|
625
660
|
});
|
|
626
661
|
setGenerated((res as never) ?? "");
|
|
@@ -652,13 +687,17 @@ const AiFeatureBase: FC<AiFeatureProps & AiKitShellInjectedProps> = (props) => {
|
|
|
652
687
|
length: length as RewriterLength,
|
|
653
688
|
outputLanguage: outLang as RewriteArgs["outputLanguage"],
|
|
654
689
|
};
|
|
655
|
-
|
|
690
|
+
|
|
691
|
+
const featureOptions: FeatureOptions = {
|
|
656
692
|
signal,
|
|
657
693
|
onStatus,
|
|
658
694
|
context,
|
|
659
695
|
modeOverride,
|
|
660
696
|
onDeviceTimeoutOverride: onDeviceTimeout,
|
|
661
|
-
}
|
|
697
|
+
};
|
|
698
|
+
|
|
699
|
+
// Normal single-pass rewrite
|
|
700
|
+
const out = await rewrite(args, featureOptions);
|
|
662
701
|
return out.result;
|
|
663
702
|
});
|
|
664
703
|
setGenerated((res as never) ?? "");
|
package/tsup.config.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { defineConfig } from "tsup";
|
|
|
2
2
|
|
|
3
3
|
export default defineConfig({
|
|
4
4
|
// Copy non-hashed global CSS so consumers can import it (like Mantine styles)
|
|
5
|
-
onSuccess:
|
|
5
|
+
onSuccess:
|
|
6
|
+
"node -e \"const fs=require('fs'); const path=require('path'); fs.mkdirSync('dist',{recursive:true}); fs.copyFileSync(path.join('src','styles','ai-kit-ui.css'), path.join('dist','ai-kit-ui.css'));\"",
|
|
6
7
|
|
|
7
8
|
entry: ["src/index.tsx"],
|
|
8
9
|
format: ["cjs", "esm"],
|