@fe-free/ai 4.1.22 → 4.1.24

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,23 @@
1
1
  # @fe-free/ai
2
2
 
3
+ ## 4.1.24
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: ai
8
+ - @fe-free/core@4.1.24
9
+ - @fe-free/icons@4.1.24
10
+ - @fe-free/tool@4.1.24
11
+
12
+ ## 4.1.23
13
+
14
+ ### Patch Changes
15
+
16
+ - feat: ai
17
+ - @fe-free/core@4.1.23
18
+ - @fe-free/icons@4.1.23
19
+ - @fe-free/tool@4.1.23
20
+
3
21
  ## 4.1.22
4
22
 
5
23
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/ai",
3
- "version": "4.1.22",
3
+ "version": "4.1.24",
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.22"
22
+ "@fe-free/core": "4.1.24"
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.22",
33
- "@fe-free/tool": "4.1.22"
32
+ "@fe-free/icons": "4.1.24",
33
+ "@fe-free/tool": "4.1.24"
34
34
  },
35
35
  "scripts": {
36
36
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -5,6 +5,7 @@ import {
5
5
  EnumChatMessageStatus,
6
6
  EnumChatMessageType,
7
7
  generateUUID,
8
+ Markdown,
8
9
  MessageActions,
9
10
  Messages,
10
11
  MSender,
@@ -121,7 +122,7 @@ function Component() {
121
122
  Add New Session
122
123
  </Button>
123
124
  </div>
124
- <div className="h-[800px] w-[500px] border border-red-500">
125
+ <div className="h-[800px] w-[500px] max-w-full border border-red-500">
125
126
  <Chat
126
127
  end={
127
128
  <div
@@ -160,11 +161,11 @@ function Component() {
160
161
  }}
161
162
  renderMessageOfAI={({ message }) => {
162
163
  return (
163
- <div className="p-2">
164
+ <div className="max-w-full p-2">
164
165
  <div>
165
166
  status: {message.status} session_id: {message.ai?.session_id}
166
167
  </div>
167
- <pre className="whitespace-pre-wrap">{message.ai?.data?.text}</pre>
168
+ <Markdown content={message.ai?.data?.text || ''} />
168
169
  <div className="flex gap-2">
169
170
  <MessageActions.Copy value={message.ai?.data?.text || ''} />
170
171
  <MessageActions.Like
@@ -45,7 +45,9 @@ function Actions(
45
45
  type="primary"
46
46
  shape="circle"
47
47
  icon={<Icons component={IconRecord} />}
48
- onClick={() => setType('record')}
48
+ onClick={() => {
49
+ setType('record');
50
+ }}
49
51
  />
50
52
  ) : (
51
53
  <Button
@@ -63,7 +63,7 @@ function MSender(originProps: MSenderProps) {
63
63
  <Text {...props} refText={refText} />
64
64
  </div>
65
65
  <Actions {...props} refText={refText} type={type} setType={setType} />
66
- {type === 'record' && <RecordAction {...props} setType={setType} />}
66
+ {type === 'record' && <RecordAction {...props} refText={refText} setType={setType} />}
67
67
  </div>
68
68
  {statement && <div className="mt-1 text-center text-xs text-04">*{statement}</div>}
69
69
  </div>
@@ -1,13 +1,16 @@
1
1
  import Icons from '@fe-free/icons';
2
2
  import { Button } from 'antd';
3
3
  import classNames from 'classnames';
4
+ import type { RefObject } from 'react';
4
5
  import { useCallback, useEffect, useRef, useState } from 'react';
5
6
  import { RecordLoading } from '../helper';
6
7
  import IconKeyboard from '../svgs/keyboard.svg?react';
7
8
  import type { MSenderProps } from './types';
8
9
 
9
- function RecordAction(props: MSenderProps & { setType }) {
10
- const { allowSpeech, setType } = props;
10
+ function RecordAction(
11
+ props: MSenderProps & { setType; refText: RefObject<HTMLTextAreaElement | null> },
12
+ ) {
13
+ const { allowSpeech, setType, refText } = props;
11
14
 
12
15
  const containerRef = useRef<HTMLDivElement>(null);
13
16
  const touchStartYRef = useRef<number>(0);
@@ -126,17 +129,20 @@ function RecordAction(props: MSenderProps & { setType }) {
126
129
 
127
130
  return (
128
131
  <div
129
- className={classNames('absolute inset-0 flex items-center justify-center rounded-xl', {
130
- 'bg-red-500': isCancel,
131
- 'bg-primary': !isCancel,
132
- })}
132
+ className={classNames(
133
+ 'fea-m-sender-record absolute inset-0 flex items-center justify-center rounded-xl',
134
+ {
135
+ 'bg-red-500': isCancel,
136
+ 'bg-primary': !isCancel,
137
+ },
138
+ )}
133
139
  >
134
140
  {isRecording ? (
135
141
  <>
136
142
  <RecordLoading count={30} gap={4} />
137
143
  {isCancel && <div className="absolute top-0 -mt-[2.5em] text-red08">松开取消</div>}
138
144
  {!isCancel && (
139
- <div className="absolute top-0 -mt-[2.5em] text-03">松开发送,上移取消</div>
145
+ <div className="absolute top-0 -mt-[2.5em] text-03">松开发送&nbsp;&nbsp;上移取消</div>
140
146
  )}
141
147
  </>
142
148
  ) : (
@@ -150,6 +156,8 @@ function RecordAction(props: MSenderProps & { setType }) {
150
156
  icon={<Icons component={IconKeyboard} className="!text-xl text-white" />}
151
157
  onClick={() => {
152
158
  setType('input');
159
+
160
+ refText.current?.focus();
153
161
  }}
154
162
  className="absolute right-4"
155
163
  />
@@ -1,6 +1,7 @@
1
1
  import { Think } from '@ant-design/x';
2
2
  import Icons from '@fe-free/icons';
3
3
  import classNames from 'classnames';
4
+ import { useCallback, useEffect, useState } from 'react';
4
5
  import ThinkIcon from '../svgs/think.svg?react';
5
6
 
6
7
  interface MessageThinkProps {
@@ -18,10 +19,28 @@ function MessageThink({
18
19
  icon,
19
20
  loading,
20
21
  children,
21
- expanded,
22
+ expanded: propsExpanded,
22
23
  onClick,
23
24
  className,
24
25
  }: MessageThinkProps) {
26
+ const [expanded, setExpanded] = useState(propsExpanded || false);
27
+
28
+ useEffect(() => {
29
+ setExpanded(propsExpanded || false);
30
+ }, [propsExpanded]);
31
+
32
+ useEffect(() => {
33
+ // 如果 propsExpanded 未定义,则根据 loading 状态设置 expanded
34
+ if (propsExpanded === undefined && loading !== undefined) {
35
+ setExpanded(loading ? true : false);
36
+ }
37
+ }, [propsExpanded, loading]);
38
+
39
+ const handleClick = useCallback(() => {
40
+ setExpanded(!expanded);
41
+ onClick?.();
42
+ }, [expanded, onClick]);
43
+
25
44
  return (
26
45
  <Think
27
46
  title={title}
@@ -29,7 +48,7 @@ function MessageThink({
29
48
  loading={loading}
30
49
  blink={loading}
31
50
  expanded={expanded}
32
- onClick={onClick}
51
+ onClick={handleClick}
33
52
  className={classNames('fea-message-think', className)}
34
53
  >
35
54
  {children}