@ray-js/t-agent-ui-ray 0.0.8-beta-3 → 0.0.9-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/dist/MarkdownRender/index.less +0 -4
- package/dist/MarkdownRender/theme/light.less +2 -1
- package/dist/MessageInput/AsrInput.d.ts +1 -0
- package/dist/MessageInput/AsrInput.js +9 -5
- package/dist/MessageInput/icons/stop.svg +1 -0
- package/dist/MessageInput/index.js +34 -7
- package/dist/MessageInput/index.less +6 -2
- package/dist/tiles/BubbleTile/index.js +3 -1
- package/dist/tiles/BubbleTile/index.less +8 -0
- package/package.json +2 -2
|
@@ -12,7 +12,8 @@ export default function AsrInput(props) {
|
|
|
12
12
|
closeMore,
|
|
13
13
|
hasMore,
|
|
14
14
|
text,
|
|
15
|
-
setText
|
|
15
|
+
setText,
|
|
16
|
+
onAbort
|
|
16
17
|
} = props;
|
|
17
18
|
const {
|
|
18
19
|
state,
|
|
@@ -65,16 +66,19 @@ export default function AsrInput(props) {
|
|
|
65
66
|
onTouchCancel: release,
|
|
66
67
|
onTouchEnd: release
|
|
67
68
|
}), /*#__PURE__*/React.createElement(Button, {
|
|
68
|
-
disabled: sendDisabled
|
|
69
|
+
disabled: sendDisabled,
|
|
69
70
|
"data-testid": "t-agent-message-input-asr-button-right",
|
|
70
71
|
className: cx('t-agent-message-input-button', {
|
|
71
72
|
't-agent-message-input-button-voice-send': state === 'pending',
|
|
72
|
-
't-agent-message-input-button-hide': state === 'recording' || !hasMore && state !== 'pending',
|
|
73
|
+
't-agent-message-input-button-hide': (state === 'recording' || !hasMore && state !== 'pending') && !responding,
|
|
73
74
|
't-agent-message-input-button-more': state === 'init' && hasMore,
|
|
74
|
-
't-agent-message-input-button-more-open': state === 'init' && moreOpen
|
|
75
|
+
't-agent-message-input-button-more-open': state === 'init' && moreOpen,
|
|
76
|
+
't-agent-message-input-button-stop': state === 'init' && responding
|
|
75
77
|
}),
|
|
76
78
|
onClick: () => {
|
|
77
|
-
if (
|
|
79
|
+
if (responding) {
|
|
80
|
+
onAbort();
|
|
81
|
+
} else if (state === 'init' && hasMore) {
|
|
78
82
|
onMoreClick();
|
|
79
83
|
} else {
|
|
80
84
|
props.onSend();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#7b7c7e" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-square"><rect width="18" height="18" x="3" y="3" rx="2"/></svg>
|
|
@@ -4,9 +4,9 @@ import "core-js/modules/esnext.iterator.map.js";
|
|
|
4
4
|
import "core-js/modules/web.dom-collections.iterator.js";
|
|
5
5
|
import './index.less';
|
|
6
6
|
import { Button, View } from '@ray-js/components';
|
|
7
|
-
import React, { useState } from 'react';
|
|
7
|
+
import React, { useRef, useState } from 'react';
|
|
8
8
|
import { Image, Input, ScrollView } from '@ray-js/ray';
|
|
9
|
-
import { Asr } from '@ray-js/t-agent-plugin-assistant';
|
|
9
|
+
import { Asr, AbortController } from '@ray-js/t-agent-plugin-assistant';
|
|
10
10
|
import cx from 'clsx';
|
|
11
11
|
import PrivateImage from '../PrivateImage';
|
|
12
12
|
import imageSvg from './icons/image.svg';
|
|
@@ -29,6 +29,7 @@ export default function MessageInput(props) {
|
|
|
29
29
|
setUploaded,
|
|
30
30
|
upload
|
|
31
31
|
} = attachmentInput;
|
|
32
|
+
const acRef = useRef(null);
|
|
32
33
|
const [responding, setResponding] = useState(false);
|
|
33
34
|
const [mode, setMode] = useState('text');
|
|
34
35
|
const agent = useChatAgent();
|
|
@@ -51,8 +52,16 @@ export default function MessageInput(props) {
|
|
|
51
52
|
setUploaded([]);
|
|
52
53
|
setText('');
|
|
53
54
|
setResponding(true);
|
|
55
|
+
const ac = new AbortController();
|
|
56
|
+
acRef.current = ac;
|
|
57
|
+
ac.signal.addEventListener('abort', () => {
|
|
58
|
+
if (acRef.current === ac) {
|
|
59
|
+
acRef.current = null;
|
|
60
|
+
}
|
|
61
|
+
setResponding(false);
|
|
62
|
+
});
|
|
54
63
|
try {
|
|
55
|
-
await agent.pushInputBlocks(inputBlocks);
|
|
64
|
+
await agent.pushInputBlocks(inputBlocks, ac.signal);
|
|
56
65
|
} finally {
|
|
57
66
|
if (!isUnmounted()) {
|
|
58
67
|
setResponding(false);
|
|
@@ -70,8 +79,16 @@ export default function MessageInput(props) {
|
|
|
70
79
|
setMoreOpen(false);
|
|
71
80
|
setUploaded([]);
|
|
72
81
|
setResponding(true);
|
|
82
|
+
const ac = new AbortController();
|
|
83
|
+
acRef.current = ac;
|
|
84
|
+
ac.signal.addEventListener('abort', () => {
|
|
85
|
+
if (acRef.current === ac) {
|
|
86
|
+
acRef.current = null;
|
|
87
|
+
}
|
|
88
|
+
setResponding(false);
|
|
89
|
+
});
|
|
73
90
|
try {
|
|
74
|
-
await agent.pushInputBlocks(blocks);
|
|
91
|
+
await agent.pushInputBlocks(blocks, ac.signal);
|
|
75
92
|
} finally {
|
|
76
93
|
if (!isUnmounted()) {
|
|
77
94
|
setResponding(false);
|
|
@@ -154,15 +171,20 @@ export default function MessageInput(props) {
|
|
|
154
171
|
},
|
|
155
172
|
className: "t-agent-message-input-button t-agent-message-input-button-voice"
|
|
156
173
|
})), /*#__PURE__*/React.createElement(Button, {
|
|
157
|
-
disabled: !isMore &&
|
|
174
|
+
disabled: !isMore && uploading,
|
|
158
175
|
className: cx('t-agent-message-input-button', {
|
|
159
176
|
't-agent-message-input-button-more': isMore,
|
|
160
177
|
't-agent-message-input-button-more-open': moreOpen && isMore,
|
|
161
|
-
't-agent-message-input-button-send': !isMore
|
|
178
|
+
't-agent-message-input-button-send': !isMore && !responding,
|
|
179
|
+
't-agent-message-input-button-stop': responding
|
|
162
180
|
}),
|
|
163
181
|
"data-testid": "t-agent-message-input-button-main",
|
|
164
182
|
onClick: async () => {
|
|
165
|
-
if (
|
|
183
|
+
if (responding) {
|
|
184
|
+
if (acRef.current) {
|
|
185
|
+
acRef.current.abort('User abort');
|
|
186
|
+
}
|
|
187
|
+
} else if (isMore) {
|
|
166
188
|
openMoreClick();
|
|
167
189
|
} else if (text) {
|
|
168
190
|
await send([...attachmentInput.blocks, {
|
|
@@ -180,6 +202,11 @@ export default function MessageInput(props) {
|
|
|
180
202
|
setText('');
|
|
181
203
|
setMode('text');
|
|
182
204
|
},
|
|
205
|
+
onAbort: () => {
|
|
206
|
+
if (acRef.current) {
|
|
207
|
+
acRef.current.abort('User abort');
|
|
208
|
+
}
|
|
209
|
+
},
|
|
183
210
|
moreOpen: moreOpen,
|
|
184
211
|
closeMore: () => setMoreOpen(false),
|
|
185
212
|
onMoreClick: openMoreClick,
|
|
@@ -98,6 +98,7 @@
|
|
|
98
98
|
.t-agent-message-input-button {
|
|
99
99
|
--button-size: 68rpx;
|
|
100
100
|
background: transparent;
|
|
101
|
+
transition: all ease-in-out 0.2s;
|
|
101
102
|
|
|
102
103
|
border-radius: 50%;
|
|
103
104
|
width: var(--button-size);
|
|
@@ -123,7 +124,6 @@
|
|
|
123
124
|
.t-agent-message-input-button-more {
|
|
124
125
|
background: transparent url('icons/plus.svg') no-repeat center;
|
|
125
126
|
border: 2rpx solid var(--t-agent-input-border-color);
|
|
126
|
-
transition: all ease-in-out 0.2s;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
.t-agent-message-input-button-more-open {
|
|
@@ -132,7 +132,6 @@
|
|
|
132
132
|
|
|
133
133
|
.t-agent-message-input-button-send {
|
|
134
134
|
background: var(--app-M1) url('icons/send.svg') no-repeat center;
|
|
135
|
-
transition: all ease-in-out 0.2s;
|
|
136
135
|
}
|
|
137
136
|
|
|
138
137
|
.t-agent-message-input-button-voice-send {
|
|
@@ -147,6 +146,11 @@
|
|
|
147
146
|
right: 10rpx;
|
|
148
147
|
}
|
|
149
148
|
|
|
149
|
+
.t-agent-message-input-button-stop {
|
|
150
|
+
background: rgba(0,0,0,0) url('icons/stop.svg') no-repeat center;
|
|
151
|
+
border: 2rpx solid var(--t-agent-input-border-color);
|
|
152
|
+
}
|
|
153
|
+
|
|
150
154
|
.t-agent-message-input-panel {
|
|
151
155
|
overflow: hidden;
|
|
152
156
|
height: 168rpx;
|
|
@@ -127,6 +127,8 @@ const BubbleTile = props => {
|
|
|
127
127
|
icon: 'none'
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
|
-
})
|
|
130
|
+
}), bubbleStatus === BubbleTileStatus.ABORTED && /*#__PURE__*/React.createElement(View, {
|
|
131
|
+
className: "t-agent-bubble-tile-aborted"
|
|
132
|
+
}, t('t-agent.message.bubble.aborted'))), side === 'start' && errorNode);
|
|
131
133
|
};
|
|
132
134
|
export default /*#__PURE__*/React.memo(BubbleTile);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/t-agent-ui-ray",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9-beta-1",
|
|
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": "df6f4f35caa6e62408450f14d9dcdd26f068283c"
|
|
45
45
|
}
|