@fe-free/ai 6.0.23 → 6.0.25
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 +18 -0
- package/package.json +4 -4
- package/src/sender/files.tsx +2 -1
- package/src/sender/sender.stories.tsx +14 -0
- package/src/sender/types.ts +4 -2
- package/src/stream/index.ts +9 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @fe-free/ai
|
|
2
2
|
|
|
3
|
+
## 6.0.25
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- sender
|
|
8
|
+
- @fe-free/core@6.0.25
|
|
9
|
+
- @fe-free/icons@6.0.25
|
|
10
|
+
- @fe-free/tool@6.0.25
|
|
11
|
+
|
|
12
|
+
## 6.0.24
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- feat: fetchStream
|
|
17
|
+
- @fe-free/core@6.0.24
|
|
18
|
+
- @fe-free/icons@6.0.24
|
|
19
|
+
- @fe-free/tool@6.0.24
|
|
20
|
+
|
|
3
21
|
## 6.0.23
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fe-free/ai",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.25",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"lodash-es": "^4.17.21",
|
|
18
18
|
"uuid": "^13.0.0",
|
|
19
19
|
"zustand": "^4.5.7",
|
|
20
|
-
"@fe-free/core": "6.0.
|
|
20
|
+
"@fe-free/core": "6.0.25"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"antd": "^6.2.1",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"i18next-icu": "^2.4.1",
|
|
28
28
|
"react": "^19.2.0",
|
|
29
29
|
"react-i18next": "^16.4.0",
|
|
30
|
-
"@fe-free/icons": "6.0.
|
|
31
|
-
"@fe-free/tool": "6.0.
|
|
30
|
+
"@fe-free/icons": "6.0.25",
|
|
31
|
+
"@fe-free/tool": "6.0.25"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"test": "echo \"Error: no test specified\" && exit 1",
|
package/src/sender/files.tsx
CHANGED
|
@@ -100,7 +100,7 @@ function FileUpload(
|
|
|
100
100
|
},
|
|
101
101
|
) {
|
|
102
102
|
const { allowUpload, refUpload, fileList, setFileList, uploadMaxCount } = props;
|
|
103
|
-
const { uploadAction, filesMaxCount, accept } = allowUpload || {};
|
|
103
|
+
const { uploadAction, uploadHeaders, filesMaxCount, accept } = allowUpload || {};
|
|
104
104
|
|
|
105
105
|
const { message } = App.useApp();
|
|
106
106
|
const { t } = useTranslation();
|
|
@@ -108,6 +108,7 @@ function FileUpload(
|
|
|
108
108
|
return (
|
|
109
109
|
<Upload.Dragger
|
|
110
110
|
action={uploadAction}
|
|
111
|
+
headers={uploadHeaders}
|
|
111
112
|
accept={accept}
|
|
112
113
|
fileList={fileList}
|
|
113
114
|
multiple
|
|
@@ -72,6 +72,20 @@ export const AllowUploadWithAccept: Story = {
|
|
|
72
72
|
render: (props) => <Component {...props} />,
|
|
73
73
|
};
|
|
74
74
|
|
|
75
|
+
export const AllowUploadWithHeaders: Story = {
|
|
76
|
+
args: {
|
|
77
|
+
allowUpload: {
|
|
78
|
+
uploadAction: '/api/ai-service/v1/file_upload/upload',
|
|
79
|
+
filesMaxCount: 3,
|
|
80
|
+
uploadHeaders: {
|
|
81
|
+
Authorization: 'Bearer mock-token',
|
|
82
|
+
'X-Trace-Id': 'storybook-demo',
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
render: (props) => <Component {...props} />,
|
|
87
|
+
};
|
|
88
|
+
|
|
75
89
|
export const RenderUpload: Story = {
|
|
76
90
|
args: {
|
|
77
91
|
allowUpload: {
|
package/src/sender/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { RefObject } from 'react';
|
|
1
|
+
import type { UploadProps } from 'antd';
|
|
2
|
+
import type { ReactNode, RefObject } from 'react';
|
|
3
3
|
|
|
4
4
|
interface SenderRef {
|
|
5
5
|
focus: () => void;
|
|
@@ -22,6 +22,8 @@ interface SenderProps {
|
|
|
22
22
|
allowUpload?: {
|
|
23
23
|
/** 上传文件的接口地址,约定返回的 {data: {url: string}} */
|
|
24
24
|
uploadAction?: string;
|
|
25
|
+
/** 上传文件时附带的请求头 */
|
|
26
|
+
uploadHeaders?: UploadProps['headers'];
|
|
25
27
|
/** 限制可上传文件类型,语法同 input.accept,如 image/*,.pdf */
|
|
26
28
|
accept?: string;
|
|
27
29
|
/** files 最大数量 */
|
package/src/stream/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { XRequest } from '@ant-design/x-sdk';
|
|
2
2
|
|
|
3
|
+
type StreamMessage = { event: string; data: string };
|
|
4
|
+
|
|
3
5
|
async function fetchStream(
|
|
4
6
|
url: string,
|
|
5
7
|
{
|
|
@@ -11,24 +13,25 @@ async function fetchStream(
|
|
|
11
13
|
params?: Record<string, any>;
|
|
12
14
|
headers?: Record<string, string>;
|
|
13
15
|
callbacks?: {
|
|
14
|
-
onUpdate?: ({ event, data }:
|
|
16
|
+
onUpdate?: ({ event, data }: StreamMessage, headers: Headers) => void;
|
|
17
|
+
onSuccess?: (chunks: StreamMessage[], headers: Headers) => void;
|
|
15
18
|
onError?: (error: Error, errorInfo?: any) => void;
|
|
16
19
|
};
|
|
17
20
|
},
|
|
18
21
|
) {
|
|
19
|
-
|
|
22
|
+
XRequest<any, StreamMessage>(url, {
|
|
20
23
|
...rest,
|
|
21
24
|
params: params,
|
|
22
25
|
headers: headers,
|
|
23
26
|
callbacks: {
|
|
24
|
-
onUpdate: (message,
|
|
27
|
+
onUpdate: (message, hs) => {
|
|
25
28
|
// 会存在 message 为 undefined 的情况
|
|
26
29
|
if (message) {
|
|
27
|
-
callbacks?.onUpdate?.(message,
|
|
30
|
+
callbacks?.onUpdate?.(message, hs);
|
|
28
31
|
}
|
|
29
32
|
},
|
|
30
|
-
onSuccess: () => {
|
|
31
|
-
|
|
33
|
+
onSuccess: (chunks, hs) => {
|
|
34
|
+
callbacks?.onSuccess?.(chunks, hs);
|
|
32
35
|
},
|
|
33
36
|
onError: (error, errorInfo) => {
|
|
34
37
|
console.log('XRequest onError', error);
|