@ray-js/t-agent-ui-ray 0.0.5-beta-1
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/LICENSE.md +21 -0
- package/README-zh_CN.md +14 -0
- package/README.md +14 -0
- package/dist/ChatContainer/index.d.ts +9 -0
- package/dist/ChatContainer/index.js +124 -0
- package/dist/ChatContainer/index.less +10 -0
- package/dist/CustomCardRender/index.d.ts +8 -0
- package/dist/CustomCardRender/index.js +21 -0
- package/dist/CustomCardRender/index.less +2 -0
- package/dist/EchartsBlockRender/index.js +73 -0
- package/dist/EchartsBlockRender/index.json +3 -0
- package/dist/EchartsBlockRender/index.less +26 -0
- package/dist/EchartsBlockRender/index.rjs +15 -0
- package/dist/EchartsBlockRender/index.tyml +12 -0
- package/dist/EchartsBlockRender/loading.svg +1 -0
- package/dist/LowCodeCardRender/index.d.ts +8 -0
- package/dist/LowCodeCardRender/index.js +14 -0
- package/dist/LowCodeCardRender/index.less +2 -0
- package/dist/MarkdownRender/BlockParser.d.ts +18 -0
- package/dist/MarkdownRender/BlockParser.js +261 -0
- package/dist/MarkdownRender/index.d.ts +14 -0
- package/dist/MarkdownRender/index.js +72 -0
- package/dist/MarkdownRender/index.less +417 -0
- package/dist/MarkdownRender/theme/dark.less +65 -0
- package/dist/MarkdownRender/theme/light.less +64 -0
- package/dist/MessageInput/AsrInput.d.ts +14 -0
- package/dist/MessageInput/AsrInput.js +78 -0
- package/dist/MessageInput/icons/close-circle.svg +1 -0
- package/dist/MessageInput/icons/image.svg +1 -0
- package/dist/MessageInput/icons/loading.svg +1 -0
- package/dist/MessageInput/icons/plus.svg +1 -0
- package/dist/MessageInput/icons/send.svg +1 -0
- package/dist/MessageInput/icons/text.svg +11 -0
- package/dist/MessageInput/icons/video.svg +1 -0
- package/dist/MessageInput/icons/voice-active.svg +9 -0
- package/dist/MessageInput/icons/voice.svg +1 -0
- package/dist/MessageInput/index.d.ts +9 -0
- package/dist/MessageInput/index.js +246 -0
- package/dist/MessageInput/index.less +289 -0
- package/dist/MessageList/index.d.ts +12 -0
- package/dist/MessageList/index.js +61 -0
- package/dist/MessageList/index.less +19 -0
- package/dist/MessageRender/index.d.ts +10 -0
- package/dist/MessageRender/index.js +34 -0
- package/dist/MessageRender/index.less +14 -0
- package/dist/PrivateImage/index.d.ts +8 -0
- package/dist/PrivateImage/index.js +113 -0
- package/dist/TileRender/index.d.ts +11 -0
- package/dist/TileRender/index.js +32 -0
- package/dist/TileRender/index.less +4 -0
- package/dist/cards/WorkflowReplyCard/index.d.ts +11 -0
- package/dist/cards/WorkflowReplyCard/index.js +67 -0
- package/dist/cards/WorkflowReplyCard/index.less +37 -0
- package/dist/cards/map.d.ts +5 -0
- package/dist/cards/map.js +4 -0
- package/dist/contexts.d.ts +11 -0
- package/dist/contexts.js +16 -0
- package/dist/global.d.ts +19 -0
- package/dist/hooks/context.d.ts +11 -0
- package/dist/hooks/context.js +40 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.js +3 -0
- package/dist/hooks/useAsrInput.d.ts +38 -0
- package/dist/hooks/useAsrInput.js +111 -0
- package/dist/hooks/useBlockInput.d.ts +18 -0
- package/dist/hooks/useBlockInput.js +148 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +14 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.js +3 -0
- package/dist/renderOption.d.ts +2 -0
- package/dist/renderOption.js +76 -0
- package/dist/tiles/BubbleTile/Feedback.d.ts +8 -0
- package/dist/tiles/BubbleTile/Feedback.js +39 -0
- package/dist/tiles/BubbleTile/feedback.less +35 -0
- package/dist/tiles/BubbleTile/index.d.ts +6 -0
- package/dist/tiles/BubbleTile/index.js +123 -0
- package/dist/tiles/BubbleTile/index.less +56 -0
- package/dist/tiles/BubbleTile/notice.svg +1 -0
- package/dist/tiles/BubbleTile/thumb-down-empty.svg +1 -0
- package/dist/tiles/BubbleTile/thumb-up-fill.svg +1 -0
- package/dist/tiles/ButtonsTile/index.d.ts +5 -0
- package/dist/tiles/ButtonsTile/index.js +18 -0
- package/dist/tiles/ButtonsTile/index.less +25 -0
- package/dist/tiles/CardTile/index.d.ts +6 -0
- package/dist/tiles/CardTile/index.js +20 -0
- package/dist/tiles/CardTile/index.less +3 -0
- package/dist/tiles/DocumentsTile/index.d.ts +5 -0
- package/dist/tiles/DocumentsTile/index.js +23 -0
- package/dist/tiles/DocumentsTile/index.less +13 -0
- package/dist/tiles/ImageTile/index.d.ts +5 -0
- package/dist/tiles/ImageTile/index.js +37 -0
- package/dist/tiles/ImageTile/index.less +9 -0
- package/dist/tiles/RecommendationsTile/index.d.ts +5 -0
- package/dist/tiles/RecommendationsTile/index.js +31 -0
- package/dist/tiles/RecommendationsTile/index.less +13 -0
- package/dist/tiles/TextTile/index.d.ts +9 -0
- package/dist/tiles/TextTile/index.js +27 -0
- package/dist/tiles/TextTile/index.less +3 -0
- package/dist/tiles/TimeTile/index.d.ts +5 -0
- package/dist/tiles/TimeTile/index.js +35 -0
- package/dist/tiles/TimeTile/index.less +10 -0
- package/dist/tiles/TipTile/index.d.ts +6 -0
- package/dist/tiles/TipTile/index.js +12 -0
- package/dist/tiles/TipTile/index.less +9 -0
- package/dist/tiles/VideoTile/index.d.ts +5 -0
- package/dist/tiles/VideoTile/index.js +49 -0
- package/dist/tiles/VideoTile/index.less +37 -0
- package/dist/tiles/WorkflowTile/index.d.ts +11 -0
- package/dist/tiles/WorkflowTile/index.js +30 -0
- package/dist/tiles/WorkflowTile/index.less +31 -0
- package/dist/tiles/map.d.ts +3 -0
- package/dist/tiles/map.js +24 -0
- package/dist/types.d.ts +26 -0
- package/dist/types.js +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import "core-js/modules/es.array.reverse.js";
|
|
2
|
+
import "core-js/modules/esnext.iterator.map.js";
|
|
3
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
4
|
+
import './index.less';
|
|
5
|
+
import { View } from '@ray-js/components';
|
|
6
|
+
import React, { useMemo, useState } from 'react';
|
|
7
|
+
import { ScrollView } from '@ray-js/ray';
|
|
8
|
+
import MessageRender from '../MessageRender';
|
|
9
|
+
import { useAgentMessage, useOnEvent } from '../hooks';
|
|
10
|
+
export default function MessageList(props) {
|
|
11
|
+
const {
|
|
12
|
+
className,
|
|
13
|
+
roleSide
|
|
14
|
+
} = props;
|
|
15
|
+
const {
|
|
16
|
+
messages
|
|
17
|
+
} = useAgentMessage();
|
|
18
|
+
const [scrollAnimation, setScrollAnimation] = useState(false);
|
|
19
|
+
// 最大整数位数,用于强制滚动到底部,收到连续 scrollToBottom 时,每 10 毫秒更新一次
|
|
20
|
+
const [scrollTop, setScrollTop] = useState(() => 1000000000000000 + Math.floor(Date.now() / 10));
|
|
21
|
+
|
|
22
|
+
// 强制滚动到底部
|
|
23
|
+
useOnEvent('scrollToBottom', _ref => {
|
|
24
|
+
let {
|
|
25
|
+
animation
|
|
26
|
+
} = _ref;
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
setScrollAnimation(!!animation);
|
|
29
|
+
const top = 1000000000000000 + Math.floor(Date.now() / 10);
|
|
30
|
+
if (top !== scrollTop) {
|
|
31
|
+
setScrollTop(top);
|
|
32
|
+
}
|
|
33
|
+
}, 100);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// 使用翻转列表,让滚动和新消息出现在第一条,这样可以避免滚动到底部时的闪烁
|
|
37
|
+
const reversed = useMemo(() => [...messages].reverse(), [messages]);
|
|
38
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
39
|
+
className: "t-agent-message-list"
|
|
40
|
+
}, /*#__PURE__*/React.createElement(ScrollView, {
|
|
41
|
+
className: "".concat(className || '', " t-agent-message-list-scroll"),
|
|
42
|
+
scrollWithAnimation: scrollAnimation,
|
|
43
|
+
scrollTop: scrollTop,
|
|
44
|
+
refresherTriggered: false,
|
|
45
|
+
enableFlex: true,
|
|
46
|
+
scrollY: true
|
|
47
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
48
|
+
className: "t-agent-message-list-padding"
|
|
49
|
+
}), reversed.map((msg, index) => {
|
|
50
|
+
let side = roleSide === null || roleSide === void 0 ? void 0 : roleSide[msg.role];
|
|
51
|
+
if (!side) {
|
|
52
|
+
side = msg.role === 'user' ? 'end' : 'start';
|
|
53
|
+
}
|
|
54
|
+
return /*#__PURE__*/React.createElement(MessageRender, {
|
|
55
|
+
key: msg.id,
|
|
56
|
+
message: msg,
|
|
57
|
+
isLatestMessage: index === 0,
|
|
58
|
+
side: side
|
|
59
|
+
});
|
|
60
|
+
})));
|
|
61
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
.t-agent-message-list {
|
|
2
|
+
flex: 1;
|
|
3
|
+
overflow-y: auto;
|
|
4
|
+
overflow-x: hidden;
|
|
5
|
+
position: relative;
|
|
6
|
+
background: var(--app-B1);
|
|
7
|
+
padding: 16rpx 32rpx 0;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.t-agent-message-list-scroll {
|
|
11
|
+
display: flex;
|
|
12
|
+
width: 100%;
|
|
13
|
+
height: 100%;
|
|
14
|
+
flex-direction: column-reverse;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.t-agent-message-list-padding {
|
|
18
|
+
flex: 1
|
|
19
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import './index.less';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ChatMessageObject } from '@ray-js/t-agent';
|
|
4
|
+
interface Props {
|
|
5
|
+
message: ChatMessageObject;
|
|
6
|
+
isLatestMessage: boolean;
|
|
7
|
+
side: 'start' | 'end';
|
|
8
|
+
}
|
|
9
|
+
export default function MessageRender({ message, isLatestMessage, side }: Props): React.JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import "core-js/modules/esnext.iterator.map.js";
|
|
2
|
+
import './index.less';
|
|
3
|
+
import { View } from '@ray-js/components';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import TileRender from '../TileRender';
|
|
6
|
+
export default function MessageRender(_ref) {
|
|
7
|
+
let {
|
|
8
|
+
message,
|
|
9
|
+
isLatestMessage,
|
|
10
|
+
side
|
|
11
|
+
} = _ref;
|
|
12
|
+
const {
|
|
13
|
+
id,
|
|
14
|
+
tiles
|
|
15
|
+
} = message;
|
|
16
|
+
if (tiles.length === 0) {
|
|
17
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
18
|
+
key: id,
|
|
19
|
+
className: "t-agent-message-list-row-empty t-agent-message-list-row-".concat(side)
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
23
|
+
key: id,
|
|
24
|
+
className: "t-agent-message-list-row t-agent-message-list-row-".concat(side)
|
|
25
|
+
}, tiles.map(tile => {
|
|
26
|
+
return /*#__PURE__*/React.createElement(TileRender, {
|
|
27
|
+
tile: tile,
|
|
28
|
+
message: message,
|
|
29
|
+
side: side,
|
|
30
|
+
key: tile.id,
|
|
31
|
+
isLatestMessage: isLatestMessage
|
|
32
|
+
});
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
.t-agent-message-list-row {
|
|
2
|
+
margin-bottom: var(--t-agent-y-gap);
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
flex: 0 0 auto;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.t-agent-message-list-row-start {
|
|
9
|
+
align-items: flex-start;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.t-agent-message-list-row-end {
|
|
13
|
+
align-items: flex-end;
|
|
14
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ImageProps } from '@ray-js/components/lib/Image/props';
|
|
3
|
+
interface PrivateImageRef {
|
|
4
|
+
}
|
|
5
|
+
declare const PrivateImage: React.ForwardRefExoticComponent<ImageProps & {
|
|
6
|
+
bizType: string;
|
|
7
|
+
} & React.RefAttributes<PrivateImageRef>>;
|
|
8
|
+
export default PrivateImage;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
const _excluded = ["src", "bizType"];
|
|
4
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
5
|
+
import React, { useMemo, useRef, useState } from 'react';
|
|
6
|
+
import { Image, View } from '@ray-js/ray';
|
|
7
|
+
import { getUrlByCloudKey, isLinkExpired, parseCloudKey, isFullLink } from '@ray-js/t-agent-plugin-assistant';
|
|
8
|
+
import logger from '../logger';
|
|
9
|
+
const PrivateImage = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
10
|
+
const {
|
|
11
|
+
src,
|
|
12
|
+
bizType
|
|
13
|
+
} = props,
|
|
14
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
15
|
+
const [_tick, tick] = useState(Math.random());
|
|
16
|
+
const {
|
|
17
|
+
expired,
|
|
18
|
+
url
|
|
19
|
+
} = useMemo(() => {
|
|
20
|
+
if (!src) {
|
|
21
|
+
return {
|
|
22
|
+
expired: true,
|
|
23
|
+
url: src
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
// 初始是否过期,如果没过期,直接使用
|
|
27
|
+
if (!isLinkExpired(src)) {
|
|
28
|
+
return {
|
|
29
|
+
expired: false,
|
|
30
|
+
url: src
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 过期了尝试去缓存里取一下 url
|
|
35
|
+
const url = getUrlByCloudKey(src);
|
|
36
|
+
if (url) {
|
|
37
|
+
// 获取 url,如果获取的 url 还是过期的,那就是真的过期了
|
|
38
|
+
if (isLinkExpired(url)) {
|
|
39
|
+
return {
|
|
40
|
+
expired: true,
|
|
41
|
+
url: src
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
expired: false,
|
|
46
|
+
url
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
// 没获取到,就是真的过期了
|
|
50
|
+
return {
|
|
51
|
+
expired: true,
|
|
52
|
+
url: src
|
|
53
|
+
};
|
|
54
|
+
}, [src, _tick, bizType]);
|
|
55
|
+
const [loading, setLoading] = useState(expired);
|
|
56
|
+
const reloadedRef = useRef(false);
|
|
57
|
+
|
|
58
|
+
// useEffect(() => {
|
|
59
|
+
// if (expired && url && !reloadedRef.current) {
|
|
60
|
+
// reloadedRef.current = true;
|
|
61
|
+
// const cloudKey = parseCloudKey(url);
|
|
62
|
+
// setLoading(true);
|
|
63
|
+
// downloadSign(cloudKey, bizType)
|
|
64
|
+
// .then(
|
|
65
|
+
// () => {
|
|
66
|
+
// tick(Math.random());
|
|
67
|
+
// },
|
|
68
|
+
// err => logger.debug('PrivateImage 重新签名失败1', err)
|
|
69
|
+
// )
|
|
70
|
+
// .finally(() => {
|
|
71
|
+
// setLoading(false);
|
|
72
|
+
// });
|
|
73
|
+
// }
|
|
74
|
+
// }, [expired, url, bizType]);
|
|
75
|
+
|
|
76
|
+
if (loading || !url || !isFullLink(url)) {
|
|
77
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
78
|
+
key: url,
|
|
79
|
+
className: rest.className,
|
|
80
|
+
style: rest.style
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return /*#__PURE__*/React.createElement(Image, _extends({
|
|
84
|
+
ref: ref,
|
|
85
|
+
key: url,
|
|
86
|
+
onError: event => {
|
|
87
|
+
var _props$onError;
|
|
88
|
+
if (typeof event.detail.errMsg === 'string' && event.detail.errMsg.includes('Not Found')) {
|
|
89
|
+
if (!reloadedRef.current) {
|
|
90
|
+
logger.debug('PrivateImage 加载出错,重新签名', {
|
|
91
|
+
url,
|
|
92
|
+
errMsg: event.detail.errMsg
|
|
93
|
+
});
|
|
94
|
+
reloadedRef.current = true;
|
|
95
|
+
parseCloudKey(url); // setLoading(true);
|
|
96
|
+
// downloadSign(cloudKey, bizType)
|
|
97
|
+
// .then(
|
|
98
|
+
// signedUrl => {
|
|
99
|
+
// tick(Math.random());
|
|
100
|
+
// },
|
|
101
|
+
// err => logger.debug('PrivateImage 重新签名失败', err)
|
|
102
|
+
// )
|
|
103
|
+
// .finally(() => {
|
|
104
|
+
// setLoading(false);
|
|
105
|
+
// });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
(_props$onError = props.onError) === null || _props$onError === void 0 || _props$onError.call(props, event);
|
|
109
|
+
},
|
|
110
|
+
src: url
|
|
111
|
+
}, rest));
|
|
112
|
+
});
|
|
113
|
+
export default PrivateImage;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import './index.less';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ChatMessageObject, ChatTileObject } from '@ray-js/t-agent';
|
|
4
|
+
interface Props {
|
|
5
|
+
tile: ChatTileObject;
|
|
6
|
+
message: ChatMessageObject;
|
|
7
|
+
side: 'start' | 'end';
|
|
8
|
+
isLatestMessage?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare const _default: React.MemoExoticComponent<({ tile, message, isLatestMessage, side }: Props) => React.JSX.Element>;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import './index.less';
|
|
2
|
+
import React, { useCallback, useMemo } from 'react';
|
|
3
|
+
import { useChatAgent, useRenderOptions } from '../hooks';
|
|
4
|
+
import { TilePropsContext } from '../contexts';
|
|
5
|
+
const TileRender = _ref => {
|
|
6
|
+
let {
|
|
7
|
+
tile,
|
|
8
|
+
message,
|
|
9
|
+
isLatestMessage,
|
|
10
|
+
side
|
|
11
|
+
} = _ref;
|
|
12
|
+
const agent = useChatAgent();
|
|
13
|
+
const emitEvent = useCallback(async payload => agent.emitTileEvent(tile.id, payload), [tile.id]);
|
|
14
|
+
const {
|
|
15
|
+
renderTileAs
|
|
16
|
+
} = useRenderOptions();
|
|
17
|
+
const props = useMemo(() => {
|
|
18
|
+
return {
|
|
19
|
+
agent,
|
|
20
|
+
tile,
|
|
21
|
+
message,
|
|
22
|
+
side,
|
|
23
|
+
isLatestMessage,
|
|
24
|
+
emitEvent
|
|
25
|
+
};
|
|
26
|
+
}, [agent, tile, message, side, isLatestMessage, emitEvent]);
|
|
27
|
+
const node = renderTileAs(props);
|
|
28
|
+
return /*#__PURE__*/React.createElement(TilePropsContext.Provider, {
|
|
29
|
+
value: props
|
|
30
|
+
}, node);
|
|
31
|
+
};
|
|
32
|
+
export default /*#__PURE__*/React.memo(TileRender);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import './index.less';
|
|
2
|
+
import { ChatCardObject } from '@ray-js/t-agent';
|
|
3
|
+
import { WorkflowReplyResource } from '@ray-js/t-agent-plugin-assistant';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
interface CardData {
|
|
6
|
+
resources: WorkflowReplyResource[];
|
|
7
|
+
}
|
|
8
|
+
declare const WorkflowReplyCard: (props: {
|
|
9
|
+
card: ChatCardObject<CardData>;
|
|
10
|
+
}) => React.JSX.Element;
|
|
11
|
+
export default WorkflowReplyCard;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import "core-js/modules/esnext.iterator.map.js";
|
|
2
|
+
import './index.less';
|
|
3
|
+
import { WorkflowReplyResourceType } from '@ray-js/t-agent-plugin-assistant';
|
|
4
|
+
import { View } from '@ray-js/components';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { Image, Video } from '@ray-js/ray';
|
|
7
|
+
import { useSendAction } from '../../hooks';
|
|
8
|
+
const WorkflowReplyCard = props => {
|
|
9
|
+
const {
|
|
10
|
+
cardData
|
|
11
|
+
} = props.card;
|
|
12
|
+
const sendAction = useSendAction();
|
|
13
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
14
|
+
className: "t-agent-workflow-reply-card"
|
|
15
|
+
}, cardData.resources.map(resource => {
|
|
16
|
+
const key = "".concat(resource.url, "-").concat(resource.title);
|
|
17
|
+
switch (resource.type) {
|
|
18
|
+
case WorkflowReplyResourceType.Web:
|
|
19
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
20
|
+
key: key,
|
|
21
|
+
onClick: () => {
|
|
22
|
+
sendAction({
|
|
23
|
+
type: 'openH5',
|
|
24
|
+
url: resource.url
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
className: "t-agent-workflow-reply-card-resource t-agent-workflow-reply-card-resource-link"
|
|
28
|
+
}, resource.title);
|
|
29
|
+
case WorkflowReplyResourceType.Image:
|
|
30
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
31
|
+
key: key,
|
|
32
|
+
className: "t-agent-workflow-reply-card-image t-agent-workflow-reply-card-resource-image",
|
|
33
|
+
onClick: () => {
|
|
34
|
+
ty.previewImage({
|
|
35
|
+
urls: [resource.url],
|
|
36
|
+
current: 0
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}, /*#__PURE__*/React.createElement(Image, {
|
|
40
|
+
mode: "widthFix",
|
|
41
|
+
src: resource.url
|
|
42
|
+
}));
|
|
43
|
+
case WorkflowReplyResourceType.Video:
|
|
44
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
45
|
+
key: key,
|
|
46
|
+
className: "t-agent-workflow-reply-card-video t-agent-workflow-reply-card-resource-video"
|
|
47
|
+
}, /*#__PURE__*/React.createElement(Video, {
|
|
48
|
+
src: resource.url
|
|
49
|
+
}));
|
|
50
|
+
case WorkflowReplyResourceType.MiniProgram:
|
|
51
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
52
|
+
key: key,
|
|
53
|
+
className: "t-agent-workflow-reply-card-resource t-agent-workflow-reply-card-resource-link",
|
|
54
|
+
onClick: () => {
|
|
55
|
+
// 这里传的是小程序 url
|
|
56
|
+
sendAction({
|
|
57
|
+
type: 'openRoute',
|
|
58
|
+
url: resource.url
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}, resource.title);
|
|
62
|
+
default:
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
};
|
|
67
|
+
export default WorkflowReplyCard;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
.t-agent-workflow-reply-card {
|
|
2
|
+
width: 612rpx;
|
|
3
|
+
min-height: 88rpx;
|
|
4
|
+
font-size: 32rpx;
|
|
5
|
+
line-height: 44rpx;
|
|
6
|
+
color: var(--app-B3-N1);
|
|
7
|
+
background-color: var(--app-B3);
|
|
8
|
+
border-radius: 32rpx;
|
|
9
|
+
padding: 24rpx;
|
|
10
|
+
transition: all 0.2s ease-in-out;
|
|
11
|
+
overflow: hidden;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.t-agent-workflow-reply-card-resource {
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.t-agent-workflow-reply-card-resource-link {
|
|
19
|
+
color: #427FF7;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// iOS 14 video圆角 bug,这样写可以正确渲染圆角
|
|
23
|
+
.t-agent-workflow-reply-card-resource-video {
|
|
24
|
+
border-radius: var(--app-C1_1);
|
|
25
|
+
overflow: hidden;
|
|
26
|
+
width: 564rpx;
|
|
27
|
+
display: flex;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
.t-agent-workflow-reply-card-resource-image image {
|
|
32
|
+
width: 564rpx;
|
|
33
|
+
height: auto;
|
|
34
|
+
border-radius: var(--app-C1_1);
|
|
35
|
+
overflow: hidden;
|
|
36
|
+
margin-top: 24rpx;
|
|
37
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ChatAgent, ChatMessageObject, UIPlugin } from '@ray-js/t-agent';
|
|
3
|
+
import { AssistantPlugin, SocketStatus } from '@ray-js/t-agent-plugin-assistant';
|
|
4
|
+
import { RenderOptions, TileProps } from './types';
|
|
5
|
+
export declare const MessageContext: import("react").Context<{
|
|
6
|
+
messages: ChatMessageObject[];
|
|
7
|
+
socketStatus: SocketStatus;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const RenderContext: import("react").Context<RenderOptions>;
|
|
10
|
+
export declare const ChatAgentContext: import("react").Context<ChatAgent<UIPlugin & AssistantPlugin>>;
|
|
11
|
+
export declare const TilePropsContext: import("react").Context<TileProps<any, any>>;
|
package/dist/contexts.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
import { SocketStatus } from '@ray-js/t-agent-plugin-assistant';
|
|
3
|
+
export const MessageContext = /*#__PURE__*/createContext({
|
|
4
|
+
messages: [],
|
|
5
|
+
socketStatus: SocketStatus.WAITING
|
|
6
|
+
});
|
|
7
|
+
export const RenderContext = /*#__PURE__*/createContext({
|
|
8
|
+
renderTileAs: () => null,
|
|
9
|
+
renderCustomBlockAs: () => null,
|
|
10
|
+
renderCardAs: () => null,
|
|
11
|
+
customBlockTypes: [],
|
|
12
|
+
customCardMap: {},
|
|
13
|
+
getStaticResourceBizType: () => ''
|
|
14
|
+
});
|
|
15
|
+
export const ChatAgentContext = /*#__PURE__*/createContext({});
|
|
16
|
+
export const TilePropsContext = /*#__PURE__*/createContext({});
|
package/dist/global.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare module '*.module.less' {
|
|
2
|
+
const classes: { [key: string]: string };
|
|
3
|
+
export default classes;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
declare module '*.png' {
|
|
7
|
+
const url: string;
|
|
8
|
+
export default url;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare module '*.svg' {
|
|
12
|
+
const url: string;
|
|
13
|
+
export default url;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare module '*.jpg' {
|
|
17
|
+
const url: string;
|
|
18
|
+
export default url;
|
|
19
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TTTAction } from '@ray-js/t-agent-plugin-assistant';
|
|
2
|
+
export declare const useChatAgent: () => import("@ray-js/t-agent").ChatAgent<import("@ray-js/t-agent").UIPlugin & import("@ray-js/t-agent-plugin-assistant").AssistantPlugin>;
|
|
3
|
+
export declare const useAgentMessage: () => {
|
|
4
|
+
messages: import("@ray-js/t-agent").ChatMessageObject[];
|
|
5
|
+
socketStatus: import("@ray-js/t-agent-plugin-assistant").SocketStatus;
|
|
6
|
+
};
|
|
7
|
+
export declare const useRenderOptions: () => import("..").RenderOptions;
|
|
8
|
+
export declare const useOnEvent: (eventName: string, callback: (details: any) => void) => void;
|
|
9
|
+
export declare const useEmitEvent: () => <T extends keyof import("@ray-js/t-agent").UIEventMap>(eventName: T, detail: import("@ray-js/t-agent").UIEventMap[T]) => void;
|
|
10
|
+
export declare const useTileProps: () => import("..").TileProps<any, any>;
|
|
11
|
+
export declare const useSendAction: () => (tttAction: TTTAction) => void;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useEffect, useContext, useCallback, useRef } from 'react';
|
|
2
|
+
import { TilePropsContext, ChatAgentContext, MessageContext, RenderContext } from '../contexts';
|
|
3
|
+
export const useChatAgent = () => {
|
|
4
|
+
return useContext(ChatAgentContext);
|
|
5
|
+
};
|
|
6
|
+
export const useAgentMessage = () => {
|
|
7
|
+
return useContext(MessageContext);
|
|
8
|
+
};
|
|
9
|
+
export const useRenderOptions = () => {
|
|
10
|
+
return useContext(RenderContext);
|
|
11
|
+
};
|
|
12
|
+
export const useOnEvent = (eventName, callback) => {
|
|
13
|
+
const callbackRef = useRef(callback);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
callbackRef.current = callback;
|
|
16
|
+
});
|
|
17
|
+
const agent = useChatAgent();
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
return agent.plugins.ui.onEvent(eventName, detail => {
|
|
20
|
+
callbackRef.current(detail);
|
|
21
|
+
});
|
|
22
|
+
}, [agent, eventName, callback]);
|
|
23
|
+
};
|
|
24
|
+
export const useEmitEvent = () => {
|
|
25
|
+
const agent = useChatAgent();
|
|
26
|
+
return agent.plugins.ui.emitEvent;
|
|
27
|
+
};
|
|
28
|
+
export const useTileProps = () => {
|
|
29
|
+
return useContext(TilePropsContext);
|
|
30
|
+
};
|
|
31
|
+
export const useSendAction = () => {
|
|
32
|
+
const {
|
|
33
|
+
emitEvent
|
|
34
|
+
} = useTileProps();
|
|
35
|
+
return useCallback(tttAction => {
|
|
36
|
+
emitEvent({
|
|
37
|
+
tttAction
|
|
38
|
+
});
|
|
39
|
+
}, [emitEvent]);
|
|
40
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare enum AsrErrorCode {
|
|
3
|
+
SHORT_TIME = 0
|
|
4
|
+
}
|
|
5
|
+
export declare class AsrError extends Error {
|
|
6
|
+
readonly errorCode: AsrErrorCode;
|
|
7
|
+
constructor(errorCode: AsrErrorCode, message?: string);
|
|
8
|
+
}
|
|
9
|
+
export interface UseAsrInputOptions {
|
|
10
|
+
onError: (error: Error) => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
init 初始状态,有返回按钮
|
|
14
|
+
recording 按住说话按钮收音,无按钮
|
|
15
|
+
pending 已有文本,待发送,有清除、发送按钮
|
|
16
|
+
|
|
17
|
+
+-------------------------------------------------------+
|
|
18
|
+
| clear/send |
|
|
19
|
+
↓ |
|
|
20
|
+
+--------+ press +------------+ release +---------+
|
|
21
|
+
| init | ----------> | recording | ----------> | pending |
|
|
22
|
+
+--------+ +------------+ +---------+
|
|
23
|
+
^ | ^ |
|
|
24
|
+
| | | |
|
|
25
|
+
| | | |
|
|
26
|
+
| empty release | | press |
|
|
27
|
+
+-------------------------+ +--------------------------+
|
|
28
|
+
*/
|
|
29
|
+
export declare function useAsrInput(options: UseAsrInputOptions): {
|
|
30
|
+
text: string;
|
|
31
|
+
setText: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
32
|
+
currentText: string;
|
|
33
|
+
incomingText: string;
|
|
34
|
+
state: "pending" | "recording" | "init";
|
|
35
|
+
clear: () => void;
|
|
36
|
+
press: () => Promise<void>;
|
|
37
|
+
release: () => Promise<void>;
|
|
38
|
+
};
|