@ray-js/t-agent-ui-ray 0.1.0-beta-10 → 0.1.0-beta-12
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/dist/ChatContainer/index.d.ts +1 -0
- package/dist/ChatContainer/index.js +5 -3
- package/dist/MarkdownRender/index.d.ts +2 -0
- package/dist/MarkdownRender/index.js +5 -2
- package/dist/MessageInput/index.d.ts +1 -0
- package/dist/MessageInput/index.js +4 -2
- package/dist/MessageList/index.d.ts +3 -0
- package/dist/MessageList/index.js +52 -15
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/index.js +0 -1
- package/dist/hooks/useDebouncedFn.d.ts +1 -0
- package/dist/hooks/useDebouncedFn.js +32 -0
- package/package.json +2 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
1
2
|
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
3
|
import "core-js/modules/esnext.iterator.filter.js";
|
|
3
4
|
import "core-js/modules/esnext.iterator.map.js";
|
|
@@ -16,7 +17,8 @@ export default function ChatContainer(props) {
|
|
|
16
17
|
createAgent,
|
|
17
18
|
renderOptions = defaultRenderOptions,
|
|
18
19
|
children,
|
|
19
|
-
className
|
|
20
|
+
className,
|
|
21
|
+
style
|
|
20
22
|
} = props;
|
|
21
23
|
const [messages, setMessages] = useState([]);
|
|
22
24
|
const [agent] = useState(() => {
|
|
@@ -153,10 +155,10 @@ export default function ChatContainer(props) {
|
|
|
153
155
|
};
|
|
154
156
|
}, []);
|
|
155
157
|
return /*#__PURE__*/React.createElement(View, {
|
|
156
|
-
style: {
|
|
158
|
+
style: _objectSpread({
|
|
157
159
|
// @ts-ignore
|
|
158
160
|
'--t-agent-chat-container-keyboard-height': "".concat(keyboardHeight, "px")
|
|
159
|
-
},
|
|
161
|
+
}, style),
|
|
160
162
|
className: cx('t-agent-chat-container', className, {
|
|
161
163
|
't-agent-chat-container-keyboard-show': keyboardHeight > 0
|
|
162
164
|
})
|
|
@@ -9,6 +9,8 @@ interface Props {
|
|
|
9
9
|
text: string;
|
|
10
10
|
customBlockTypes: string[];
|
|
11
11
|
renderBlock: (block: MarkdownBlock) => React.ReactNode;
|
|
12
|
+
className?: string;
|
|
13
|
+
style?: React.CSSProperties;
|
|
12
14
|
}
|
|
13
15
|
declare const _default: React.MemoExoticComponent<(props: Props) => React.JSX.Element>;
|
|
14
16
|
export default _default;
|
|
@@ -15,7 +15,9 @@ const MarkdownRender = props => {
|
|
|
15
15
|
prefix,
|
|
16
16
|
text,
|
|
17
17
|
customBlockTypes,
|
|
18
|
-
renderBlock
|
|
18
|
+
renderBlock,
|
|
19
|
+
className,
|
|
20
|
+
style
|
|
19
21
|
} = props;
|
|
20
22
|
const [parser, setParser] = useState(() => {
|
|
21
23
|
return new BlockParser(prefix, customBlockTypes, "h2w__main h2w__".concat(theme));
|
|
@@ -28,7 +30,8 @@ const MarkdownRender = props => {
|
|
|
28
30
|
}, [text, parser]);
|
|
29
31
|
const sendAction = useSendAction();
|
|
30
32
|
return /*#__PURE__*/React.createElement(View, {
|
|
31
|
-
className: "t-agent-markdown-render"
|
|
33
|
+
className: "t-agent-markdown-render ".concat(className || ''),
|
|
34
|
+
style: style
|
|
32
35
|
}, blocks.map(block => {
|
|
33
36
|
const {
|
|
34
37
|
id,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "core-js/modules/es.string.trim.js";
|
|
1
2
|
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
3
|
import "core-js/modules/esnext.iterator.filter.js";
|
|
3
4
|
import "core-js/modules/esnext.iterator.map.js";
|
|
@@ -42,7 +43,7 @@ export default function MessageInput(props) {
|
|
|
42
43
|
}
|
|
43
44
|
});
|
|
44
45
|
const hasMore = !!agent.plugins.assistant.options.multiModal;
|
|
45
|
-
const isMore = !text.length && hasMore;
|
|
46
|
+
const isMore = !text.trim().length && hasMore;
|
|
46
47
|
const send = async inputBlocks => {
|
|
47
48
|
if (!(inputBlocks !== null && inputBlocks !== void 0 && inputBlocks.length) || attachmentInput.uploading || responding) {
|
|
48
49
|
return;
|
|
@@ -228,7 +229,8 @@ export default function MessageInput(props) {
|
|
|
228
229
|
});
|
|
229
230
|
}
|
|
230
231
|
return /*#__PURE__*/React.createElement(View, {
|
|
231
|
-
className: "".concat(props.className || '', " t-agent-message-input")
|
|
232
|
+
className: "".concat(props.className || '', " t-agent-message-input"),
|
|
233
|
+
style: props.style
|
|
232
234
|
}, /*#__PURE__*/React.createElement(View, {
|
|
233
235
|
className: "t-agent-message-input-container"
|
|
234
236
|
}, props.renderTop, !!uploaded.length && /*#__PURE__*/React.createElement(ScrollView, {
|
|
@@ -2,6 +2,9 @@ import './index.less';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
interface Props {
|
|
4
4
|
className?: string;
|
|
5
|
+
style?: React.CSSProperties;
|
|
6
|
+
wrapperClassName?: string;
|
|
7
|
+
wrapperStyle?: React.CSSProperties;
|
|
5
8
|
roleSide?: {
|
|
6
9
|
user?: 'start' | 'end' | string;
|
|
7
10
|
assistant?: 'start' | 'end' | string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import "core-js/modules/es.array.reverse.js";
|
|
2
3
|
import "core-js/modules/esnext.iterator.constructor.js";
|
|
3
4
|
import "core-js/modules/esnext.iterator.map.js";
|
|
@@ -6,21 +7,47 @@ import './index.less';
|
|
|
6
7
|
import { View } from '@ray-js/components';
|
|
7
8
|
import React, { useMemo, useRef, useState } from 'react';
|
|
8
9
|
import { ScrollView } from '@ray-js/ray';
|
|
10
|
+
import { generateId } from '@ray-js/t-agent';
|
|
11
|
+
import { isVersionMatch } from '@ray-js/t-agent-plugin-assistant';
|
|
9
12
|
import MessageRender from '../MessageRender';
|
|
10
|
-
import { useAgentMessage, useOnEvent
|
|
13
|
+
import { useAgentMessage, useOnEvent } from '../hooks';
|
|
14
|
+
import { useDebouncedFn } from '../hooks/useDebouncedFn';
|
|
15
|
+
import { useSleep } from '../hooks/useSleep';
|
|
11
16
|
export default function MessageList(props) {
|
|
12
17
|
const {
|
|
13
18
|
className,
|
|
14
|
-
roleSide
|
|
19
|
+
roleSide,
|
|
20
|
+
style,
|
|
21
|
+
wrapperClassName,
|
|
22
|
+
wrapperStyle
|
|
15
23
|
} = props;
|
|
16
24
|
const {
|
|
17
25
|
messages
|
|
18
26
|
} = useAgentMessage();
|
|
27
|
+
const [id] = useState(() => "ScrollView-".concat(generateId()));
|
|
19
28
|
const [scrollAnimation, setScrollAnimation] = useState(false);
|
|
20
29
|
// 最大整数位数,用于强制滚动到底部,收到连续 scrollToBottom 时,每 10 毫秒更新一次
|
|
21
30
|
const [scrollTop, setScrollTop] = useState(() => 1000000000000000 + Math.floor(Date.now() / 10));
|
|
22
31
|
const followNewMessageRef = useRef(true);
|
|
23
32
|
const sleep = useSleep();
|
|
33
|
+
const canIUse = useMemo(() => {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
const {
|
|
36
|
+
containerVersion
|
|
37
|
+
} = ty.getSystemInfoSync();
|
|
38
|
+
return {
|
|
39
|
+
// 在 2.27.2 版本之前,pageScrollTo 在某些场景不生效
|
|
40
|
+
scroll: containerVersion && isVersionMatch('>=2.27.2', containerVersion)
|
|
41
|
+
};
|
|
42
|
+
}, []);
|
|
43
|
+
const scroll = useDebouncedFn(animation => {
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
ty.pageScrollTo({
|
|
46
|
+
scrollTop: 0,
|
|
47
|
+
duration: animation ? 100 : 1,
|
|
48
|
+
selector: "#".concat(id)
|
|
49
|
+
});
|
|
50
|
+
}, 100);
|
|
24
51
|
|
|
25
52
|
// 强制滚动到底部
|
|
26
53
|
useOnEvent('scrollToBottom', _ref => {
|
|
@@ -32,24 +59,34 @@ export default function MessageList(props) {
|
|
|
32
59
|
if (follow && !followNewMessageRef.current) {
|
|
33
60
|
return;
|
|
34
61
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
62
|
+
if (canIUse.scroll) {
|
|
63
|
+
scroll(animation);
|
|
64
|
+
} else {
|
|
65
|
+
sleep(100).then(() => {
|
|
66
|
+
setScrollAnimation(!!animation);
|
|
67
|
+
const top = 1000000000000000 + Math.floor(Date.now() / 10);
|
|
68
|
+
if (top !== scrollTop) {
|
|
69
|
+
setScrollTop(top);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
42
73
|
});
|
|
43
74
|
|
|
44
75
|
// 使用翻转列表,让滚动和新消息出现在第一条,这样可以避免滚动到底部时的闪烁
|
|
45
76
|
const reversed = useMemo(() => [...messages].reverse(), [messages]);
|
|
77
|
+
const scrollProps = canIUse.scroll ? {} : {
|
|
78
|
+
scrollWithAnimation: scrollAnimation,
|
|
79
|
+
scrollTop
|
|
80
|
+
};
|
|
46
81
|
return /*#__PURE__*/React.createElement(View, {
|
|
47
|
-
className: "t-agent-message-list",
|
|
48
|
-
"data-testid": "t-agent-message-list"
|
|
49
|
-
|
|
82
|
+
className: "t-agent-message-list ".concat(wrapperClassName || ''),
|
|
83
|
+
"data-testid": "t-agent-message-list",
|
|
84
|
+
style: wrapperStyle
|
|
85
|
+
}, /*#__PURE__*/React.createElement(ScrollView, _extends({
|
|
50
86
|
className: "".concat(className || '', " t-agent-message-list-scroll"),
|
|
51
|
-
|
|
52
|
-
|
|
87
|
+
style: style,
|
|
88
|
+
id: id
|
|
89
|
+
}, scrollProps, {
|
|
53
90
|
refresherTriggered: false,
|
|
54
91
|
enableFlex: true,
|
|
55
92
|
scrollY: true,
|
|
@@ -57,7 +94,7 @@ export default function MessageList(props) {
|
|
|
57
94
|
// 使用了 flex-direction: column-reverse,所以滚动到顶部时,scrollTop = 0
|
|
58
95
|
followNewMessageRef.current = event.detail.scrollTop > -10;
|
|
59
96
|
}
|
|
60
|
-
}, /*#__PURE__*/React.createElement(View, {
|
|
97
|
+
}), /*#__PURE__*/React.createElement(View, {
|
|
61
98
|
className: "t-agent-message-list-padding"
|
|
62
99
|
}), reversed.map((msg, index) => {
|
|
63
100
|
let side = roleSide === null || roleSide === void 0 ? void 0 : roleSide[msg.role];
|
package/dist/hooks/index.d.ts
CHANGED
package/dist/hooks/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useDebouncedFn<T extends (...args: any[]) => any>(fn: T, delay: number): (...args: Parameters<T>) => void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
2
|
+
import { useRef, useEffect, useCallback } from 'react';
|
|
3
|
+
export function useDebouncedFn(fn, delay) {
|
|
4
|
+
const timer = useRef();
|
|
5
|
+
const fnRef = useRef(fn);
|
|
6
|
+
|
|
7
|
+
// 保证引用是最新的
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
fnRef.current = fn;
|
|
10
|
+
});
|
|
11
|
+
const debounced = useCallback(function () {
|
|
12
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
13
|
+
args[_key] = arguments[_key];
|
|
14
|
+
}
|
|
15
|
+
if (timer.current) {
|
|
16
|
+
clearTimeout(timer.current);
|
|
17
|
+
}
|
|
18
|
+
timer.current = setTimeout(() => {
|
|
19
|
+
fnRef.current(...args);
|
|
20
|
+
}, delay);
|
|
21
|
+
}, [delay]);
|
|
22
|
+
|
|
23
|
+
// 卸载时清理
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
return () => {
|
|
26
|
+
if (timer.current) {
|
|
27
|
+
clearTimeout(timer.current);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}, []);
|
|
31
|
+
return debounced;
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/t-agent-ui-ray",
|
|
3
|
-
"version": "0.1.0-beta-
|
|
3
|
+
"version": "0.1.0-beta-12",
|
|
4
4
|
"author": "Tuya.inc",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"@types/echarts": "^4.9.22",
|
|
42
42
|
"@types/markdown-it": "^14.1.1"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "34434bfc256e79bdb1c33ef9f55fb705704264f6"
|
|
45
45
|
}
|