@agentscope-ai/chat 1.1.63 → 1.1.64-beta.1779184304979
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/components/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Request/Card.tsx +5 -1
- package/components/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Response/Message.tsx +2 -1
- package/components/AgentScopeRuntimeWebUI/core/types/IChatAnywhere.ts +6 -0
- package/components/DefaultCards/Files/index.tsx +5 -1
- package/lib/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Request/Card.js +8 -2
- package/lib/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Response/Message.js +6 -1
- package/lib/AgentScopeRuntimeWebUI/core/types/IChatAnywhere.d.ts +9 -0
- package/lib/DefaultCards/Files/index.js +5 -1
- package/package.json +1 -1
|
@@ -3,10 +3,13 @@ import { AgentScopeRuntimeContentType, IAgentScopeRuntimeRequest } from '../type
|
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
4
|
import { Bubble } from '@agentscope-ai/chat';
|
|
5
5
|
import Actions from './Actions';
|
|
6
|
+
import { useChatAnywhereOptions } from '../../Context/ChatAnywhereOptionsContext';
|
|
6
7
|
|
|
7
8
|
export default function AgentScopeRuntimeRequestCard(props: {
|
|
8
9
|
data: IAgentScopeRuntimeRequest;
|
|
9
10
|
}) {
|
|
11
|
+
const onFileCardClick = useChatAnywhereOptions(v => v.api?.onFileCardClick);
|
|
12
|
+
|
|
10
13
|
const cards = useMemo(() => {
|
|
11
14
|
|
|
12
15
|
return props.data.input[0].content.reduce<any>((p, c) => {
|
|
@@ -63,6 +66,7 @@ export default function AgentScopeRuntimeRequestCard(props: {
|
|
|
63
66
|
p.push({
|
|
64
67
|
code: 'Files',
|
|
65
68
|
data: [{ url: c.file_url, name: c.file_name || c.fileName, size: c.file_size }],
|
|
69
|
+
onClick: onFileCardClick,
|
|
66
70
|
});
|
|
67
71
|
} else {
|
|
68
72
|
fileCard.data.push({ url: c.file_url, name: c.file_name || c.fileName, size: c.file_size });
|
|
@@ -70,7 +74,7 @@ export default function AgentScopeRuntimeRequestCard(props: {
|
|
|
70
74
|
}
|
|
71
75
|
return p;
|
|
72
76
|
}, []);
|
|
73
|
-
}, [props.data.input]);
|
|
77
|
+
}, [props.data.input, onFileCardClick]);
|
|
74
78
|
|
|
75
79
|
if (!cards?.length) return null;
|
|
76
80
|
|
|
@@ -9,6 +9,7 @@ import { useChatAnywhereOptions } from "../../Context/ChatAnywhereOptionsContext
|
|
|
9
9
|
|
|
10
10
|
const Message = React.memo(function ({ data }: { data: IAgentScopeRuntimeMessage }) {
|
|
11
11
|
const replaceMediaURL = useChatAnywhereOptions(v => v.api?.replaceMediaURL);
|
|
12
|
+
const onFileCardClick = useChatAnywhereOptions(v => v.api?.onFileCardClick);
|
|
12
13
|
const formatMediaURL = React.useCallback((url?: string) => {
|
|
13
14
|
if (!url) return url;
|
|
14
15
|
return replaceMediaURL?.(url) || url;
|
|
@@ -36,7 +37,7 @@ const Message = React.memo(function ({ data }: { data: IAgentScopeRuntimeMessage
|
|
|
36
37
|
url: formatMediaURL(item.file_url),
|
|
37
38
|
name: item.file_name || item.fileName || item.file_id,
|
|
38
39
|
size: item.file_size,
|
|
39
|
-
}]}></Files>
|
|
40
|
+
}]} onClick={onFileCardClick}></Files>
|
|
40
41
|
case AgentScopeRuntimeContentType.AUDIO:
|
|
41
42
|
return <Audios key={index} data={[{ src: formatMediaURL(item.audio_url || item.data) }]}></Audios>
|
|
42
43
|
default:
|
|
@@ -68,6 +68,12 @@ export interface IAgentScopeRuntimeWebUIAPIOptions {
|
|
|
68
68
|
* @descriptionEn Custom media URL transformer (e.g. sign URL, replace CDN domain)
|
|
69
69
|
*/
|
|
70
70
|
replaceMediaURL?: (url: string) => string;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @description 自定义文件点击事件(桌面端可通过此钩子调用原生 API 打开文件链接),不传则默认 window.open
|
|
74
|
+
* @descriptionEn Custom file click handler (desktop apps can use native APIs to open file URLs), defaults to window.open
|
|
75
|
+
*/
|
|
76
|
+
onFileCardClick?: (file: { url?: string; name?: string; size?: number }) => void;
|
|
71
77
|
}
|
|
72
78
|
|
|
73
79
|
/**
|
|
@@ -56,7 +56,11 @@ export default function Files(props) {
|
|
|
56
56
|
|
|
57
57
|
{
|
|
58
58
|
fileInfo.url && <div className={`${prefixCls}-download`} onClick={() => {
|
|
59
|
-
|
|
59
|
+
if (props.onClick) {
|
|
60
|
+
props.onClick(fileInfo);
|
|
61
|
+
} else {
|
|
62
|
+
window.open(fileInfo.url, '_blank');
|
|
63
|
+
}
|
|
60
64
|
}}>
|
|
61
65
|
<SparkDownloadLine />
|
|
62
66
|
</div>
|
|
@@ -2,10 +2,15 @@ import { AgentScopeRuntimeContentType } from "../types";
|
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
3
|
import { Bubble } from "../../../..";
|
|
4
4
|
import Actions from "./Actions";
|
|
5
|
+
import { useChatAnywhereOptions } from "../../Context/ChatAnywhereOptionsContext";
|
|
5
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
7
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
7
8
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
9
|
export default function AgentScopeRuntimeRequestCard(props) {
|
|
10
|
+
var onFileCardClick = useChatAnywhereOptions(function (v) {
|
|
11
|
+
var _v$api;
|
|
12
|
+
return (_v$api = v.api) === null || _v$api === void 0 ? void 0 : _v$api.onFileCardClick;
|
|
13
|
+
});
|
|
9
14
|
var cards = useMemo(function () {
|
|
10
15
|
return props.data.input[0].content.reduce(function (p, c) {
|
|
11
16
|
if (c.type === AgentScopeRuntimeContentType.TEXT) {
|
|
@@ -81,7 +86,8 @@ export default function AgentScopeRuntimeRequestCard(props) {
|
|
|
81
86
|
url: c.file_url,
|
|
82
87
|
name: c.file_name || c.fileName,
|
|
83
88
|
size: c.file_size
|
|
84
|
-
}]
|
|
89
|
+
}],
|
|
90
|
+
onClick: onFileCardClick
|
|
85
91
|
});
|
|
86
92
|
} else {
|
|
87
93
|
fileCard.data.push({
|
|
@@ -93,7 +99,7 @@ export default function AgentScopeRuntimeRequestCard(props) {
|
|
|
93
99
|
}
|
|
94
100
|
return p;
|
|
95
101
|
}, []);
|
|
96
|
-
}, [props.data.input]);
|
|
102
|
+
}, [props.data.input, onFileCardClick]);
|
|
97
103
|
if (!(cards !== null && cards !== void 0 && cards.length)) return null;
|
|
98
104
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
99
105
|
children: [/*#__PURE__*/_jsx(Bubble, {
|
|
@@ -15,6 +15,10 @@ var Message = /*#__PURE__*/React.memo(function (_ref) {
|
|
|
15
15
|
var _v$api;
|
|
16
16
|
return (_v$api = v.api) === null || _v$api === void 0 ? void 0 : _v$api.replaceMediaURL;
|
|
17
17
|
});
|
|
18
|
+
var onFileCardClick = useChatAnywhereOptions(function (v) {
|
|
19
|
+
var _v$api2;
|
|
20
|
+
return (_v$api2 = v.api) === null || _v$api2 === void 0 ? void 0 : _v$api2.onFileCardClick;
|
|
21
|
+
});
|
|
18
22
|
var formatMediaURL = React.useCallback(function (url) {
|
|
19
23
|
if (!url) return url;
|
|
20
24
|
return (replaceMediaURL === null || replaceMediaURL === void 0 ? void 0 : replaceMediaURL(url)) || url;
|
|
@@ -52,7 +56,8 @@ var Message = /*#__PURE__*/React.memo(function (_ref) {
|
|
|
52
56
|
url: formatMediaURL(item.file_url),
|
|
53
57
|
name: item.file_name || item.fileName || item.file_id,
|
|
54
58
|
size: item.file_size
|
|
55
|
-
}]
|
|
59
|
+
}],
|
|
60
|
+
onClick: onFileCardClick
|
|
56
61
|
}, index);
|
|
57
62
|
case AgentScopeRuntimeContentType.AUDIO:
|
|
58
63
|
return /*#__PURE__*/_jsx(Audios, {
|
|
@@ -58,6 +58,15 @@ export interface IAgentScopeRuntimeWebUIAPIOptions {
|
|
|
58
58
|
* @descriptionEn Custom media URL transformer (e.g. sign URL, replace CDN domain)
|
|
59
59
|
*/
|
|
60
60
|
replaceMediaURL?: (url: string) => string;
|
|
61
|
+
/**
|
|
62
|
+
* @description 自定义文件点击事件(桌面端可通过此钩子调用原生 API 打开文件链接),不传则默认 window.open
|
|
63
|
+
* @descriptionEn Custom file click handler (desktop apps can use native APIs to open file URLs), defaults to window.open
|
|
64
|
+
*/
|
|
65
|
+
onFileCardClick?: (file: {
|
|
66
|
+
url?: string;
|
|
67
|
+
name?: string;
|
|
68
|
+
size?: number;
|
|
69
|
+
}) => void;
|
|
61
70
|
}
|
|
62
71
|
/**
|
|
63
72
|
* @description 主题配置选项
|
|
@@ -45,7 +45,11 @@ export default function Files(props) {
|
|
|
45
45
|
}), fileInfo.url && /*#__PURE__*/_jsx("div", {
|
|
46
46
|
className: "".concat(prefixCls, "-download"),
|
|
47
47
|
onClick: function onClick() {
|
|
48
|
-
|
|
48
|
+
if (props.onClick) {
|
|
49
|
+
props.onClick(fileInfo);
|
|
50
|
+
} else {
|
|
51
|
+
window.open(fileInfo.url, '_blank');
|
|
52
|
+
}
|
|
49
53
|
},
|
|
50
54
|
children: /*#__PURE__*/_jsx(SparkDownloadLine, {})
|
|
51
55
|
})]
|
package/package.json
CHANGED