@fe-free/ai 4.1.31 → 4.1.32

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @fe-free/ai
2
2
 
3
+ ## 4.1.32
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: ai
8
+ - @fe-free/core@4.1.32
9
+ - @fe-free/icons@4.1.32
10
+ - @fe-free/tool@4.1.32
11
+
3
12
  ## 4.1.31
4
13
 
5
14
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/ai",
3
- "version": "4.1.31",
3
+ "version": "4.1.32",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
@@ -19,7 +19,7 @@
19
19
  "lodash-es": "^4.17.21",
20
20
  "uuid": "^13.0.0",
21
21
  "zustand": "^4.5.7",
22
- "@fe-free/core": "4.1.31"
22
+ "@fe-free/core": "4.1.32"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "antd": "^5.27.1",
@@ -29,8 +29,8 @@
29
29
  "i18next-icu": "^2.4.1",
30
30
  "react": "^19.2.0",
31
31
  "react-i18next": "^16.4.0",
32
- "@fe-free/icons": "4.1.31",
33
- "@fe-free/tool": "4.1.31"
32
+ "@fe-free/icons": "4.1.32",
33
+ "@fe-free/tool": "4.1.32"
34
34
  },
35
35
  "scripts": {
36
36
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -1,3 +1,4 @@
1
+ import type { ComponentProps, XMarkdownProps } from '@ant-design/x-markdown';
1
2
  import { CustomMarkdown } from '@fe-free/ai';
2
3
  import type { Meta, StoryObj } from '@storybook/react-vite';
3
4
 
@@ -439,14 +440,14 @@ export const KnowledgeWithoutData: Story = {
439
440
  },
440
441
  };
441
442
 
442
- export const PPTPartialHtml: Story = {
443
+ export const GetComponents: Story = {
443
444
  args: {
444
445
  content: `
445
446
  # 测试
446
447
 
447
448
  啊沙发沙发发按时发
448
449
 
449
- \`\`\`pptpartialhtml
450
+ \`\`\`balabala
450
451
  <!DOCTYPE html>
451
452
  <html>
452
453
  <head>
@@ -456,66 +457,29 @@ export const PPTPartialHtml: Story = {
456
457
  <div>案发时发发</div>
457
458
  <div>案发时发发</div>
458
459
  <div>案发时发发</div>
459
- <div>案发时发发</div>
460
- <div>案发时发发</div>
461
- <div>案发时发发</div>
462
- <div>案发时发发</div>
463
- <div>案发时发发</div>
464
- <div>案发时发发</div>
465
- <div>案发时发发</div>
466
- <div>案发时发发</div>
467
- <div>案发时发发</div>
468
- <div>案发时发发</div>
469
- <div>案发时发发</div>
470
- <div>案发时发发</div>
471
- <div>案发时发发</div>
472
- <div>案发时发发</div>
473
- <div>案发时发发</div>
474
- <div>案发时发发</div>
475
- <div>案发时发发</div>
476
- <div>案发时发发</div>
477
- <div>案发时发发</div>
478
- <div>案发时发发</div>
479
- <div>案发时发发</div>
480
- <div>案发时发发</div>
481
- <div>案发时发发</div>
482
- <div>案发时发发</div>
483
- <div>案发时发发</div>
484
- <div>案发时发发</div>
485
- <div>案发时发发</div>
486
- <div>案发时发发</div>
487
- <div>案发时发发</div>
488
- <div>案发时发发</div>
489
- <div>案发时发发</div>
490
- <div>案发时发发</div>
491
- <div>案发时发发</div>
492
- <div>案发时发发</div>
493
- <div>案发时发发</div>
494
- <div>案发时发发</div>
495
- <div>案发时发发</div>
496
- <div>案发时发发</div>
497
- <div>案发时发发</div>
498
- <div>案发时发发</div>
499
- <div>案发时发发</div>
500
- <div>案发时发发</div>
501
- <div>案发时发发</div>
502
- <div>案发时发发</div>
503
- <div>案发时发发</div>
504
- <div>案发时发发</div>
505
- <div>案发时发发</div>
506
- <div>案发时发发</div>
507
- <div>案发时发发</div>
508
- <div>案发时发发</div>
509
- <div>案发时发发</div>
510
- <div>案发时发发</div>
511
- </body>
512
- </html>
460
+ <div>案发时发
513
461
  \`\`\`
514
462
 
515
463
  ababa
516
464
  `,
517
- onKnowledgeRef: (id?: string) => {
518
- console.log('onKnowledgeRef', id);
465
+ getComponents: (components: XMarkdownProps['components']) => {
466
+ return {
467
+ ...components,
468
+ code: (props: ComponentProps) => {
469
+ const CodeComponent = components?.code as React.ComponentType<ComponentProps>;
470
+ const lang = props.className?.match(/language-(\w+)/)?.[1] || '';
471
+
472
+ if (lang === 'balabala') {
473
+ return <div className="bg-red-100">{props.children}</div>;
474
+ }
475
+
476
+ if (!CodeComponent) {
477
+ return null;
478
+ }
479
+
480
+ return <CodeComponent {...props} />;
481
+ },
482
+ };
519
483
  },
520
484
  },
521
485
  };
@@ -13,6 +13,7 @@ interface MarkdownProps {
13
13
  content?: string;
14
14
  isStreaming?: boolean;
15
15
  components?: XMarkdownProps['components'];
16
+ getComponents?: (components: XMarkdownProps['components']) => XMarkdownProps['components'];
16
17
  }
17
18
 
18
19
  function useMarkdownTheme() {
@@ -30,7 +31,18 @@ function useMarkdownTheme() {
30
31
  return [className];
31
32
  }
32
33
 
33
- function Markdown({ content, isStreaming, components: propsComponents }: MarkdownProps) {
34
+ function defaultGetComponents(components: XMarkdownProps['components']) {
35
+ return {
36
+ ...components,
37
+ };
38
+ }
39
+
40
+ function Markdown({
41
+ content,
42
+ isStreaming,
43
+ components: propsComponents,
44
+ getComponents = defaultGetComponents,
45
+ }: MarkdownProps) {
34
46
  const [className] = useMarkdownTheme();
35
47
 
36
48
  const config = useMemo(() => {
@@ -46,12 +58,12 @@ function Markdown({ content, isStreaming, components: propsComponents }: Markdow
46
58
  }, [isStreaming]);
47
59
 
48
60
  const components = useMemo(() => {
49
- return {
61
+ return getComponents({
50
62
  code: CodeComponent,
51
63
  think: ThinkComponent,
52
- ...(propsComponents || {}),
53
- };
54
- }, [propsComponents]);
64
+ ...propsComponents,
65
+ });
66
+ }, [getComponents, propsComponents]);
55
67
 
56
68
  return (
57
69
  <XMarkdown