@ray-js/t-agent-ui-ray 0.2.0-beta-13 → 0.2.0-beta-15

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.
@@ -4,6 +4,7 @@ import { Button, View } from '@ray-js/ray';
4
4
  import cx from 'clsx';
5
5
  import { useTranslate } from '../../hooks';
6
6
  import { WaveformVisualizer } from './WaveformVisualizer';
7
+ import logger from '../../logger';
7
8
  const AsrInput = props => {
8
9
  const touchRef = useRef({
9
10
  startAt: 0,
@@ -72,8 +73,14 @@ const AsrInput = props => {
72
73
  const touchY = touch.pageY;
73
74
  setCancel(touchRef.current.y - touchY > 100);
74
75
  },
75
- onTouchCancel: onVoiceTouchEnd,
76
- onTouchEnd: onVoiceTouchEnd
76
+ onTouchCancel: event => {
77
+ logger.debug('MessageInputAIStream onTouchCancel');
78
+ onVoiceTouchEnd(event);
79
+ },
80
+ onTouchEnd: event => {
81
+ logger.debug('MessageInputAIStream onTouchEnd');
82
+ onVoiceTouchEnd(event);
83
+ }
77
84
  }, /*#__PURE__*/React.createElement(View, {
78
85
  className: "t-agent-message-input-ptt-text"
79
86
  }, " ", t('t-agent.input.asr.ptt')), /*#__PURE__*/React.createElement(View, {
@@ -36,20 +36,17 @@ var InputAction = /*#__PURE__*/function (InputAction) {
36
36
  InputAction["ABORT"] = "abort";
37
37
  InputAction["TEXT_END"] = "text_end";
38
38
  InputAction["ABORT_DONE"] = "abort_done";
39
- InputAction["NETWORK_CHANGE"] = "network_change";
40
39
  return InputAction;
41
40
  }(InputAction || {});
42
41
  const transitions = {
43
42
  [InputState.PENDING]: {
44
43
  [InputAction.SEND]: InputState.RESPONDING,
45
44
  [InputAction.RECORD]: InputState.RECORDING,
46
- [InputAction.NETWORK_CHANGE]: InputState.PENDING,
47
45
  // 这个变更是为了兼容 pushInputBlocks 结束的场景,没有实际意义
48
46
  [InputAction.TEXT_END]: InputState.PENDING
49
47
  },
50
48
  [InputState.RECORDING]: {
51
49
  [InputAction.RECORD_TIMEOUT]: InputState.ASR,
52
- [InputAction.NETWORK_CHANGE]: InputState.PENDING,
53
50
  [InputAction.RECORD_CANCEL]: InputState.PENDING,
54
51
  [InputAction.RECORD_CONFIRM]: InputState.ASR,
55
52
  [InputAction.ABORT]: InputState.ABORTING,
@@ -58,17 +55,14 @@ const transitions = {
58
55
  [InputState.ASR]: {
59
56
  [InputAction.ASR_END]: InputState.RESPONDING,
60
57
  [InputAction.ASR_ERROR]: InputState.PENDING,
61
- [InputAction.ABORT]: InputState.ABORTING,
62
- [InputAction.NETWORK_CHANGE]: InputState.PENDING
58
+ [InputAction.ABORT]: InputState.ABORTING
63
59
  },
64
60
  [InputState.RESPONDING]: {
65
61
  [InputAction.ABORT]: InputState.ABORTING,
66
- [InputAction.TEXT_END]: InputState.PENDING,
67
- [InputAction.NETWORK_CHANGE]: InputState.PENDING
62
+ [InputAction.TEXT_END]: InputState.PENDING
68
63
  },
69
64
  [InputState.ABORTING]: {
70
- [InputAction.ABORT_DONE]: InputState.PENDING,
71
- [InputAction.NETWORK_CHANGE]: InputState.PENDING
65
+ [InputAction.ABORT_DONE]: InputState.PENDING
72
66
  }
73
67
  };
74
68
  export default function MessageInputAIStream(props) {
@@ -123,14 +117,6 @@ export default function MessageInputAIStream(props) {
123
117
  const agent = useChatAgent();
124
118
  const emitEvent = useEmitEvent();
125
119
  const isUnmounted = useIsUnmounted();
126
- useOnEvent('networkChange', _ref => {
127
- let {
128
- online
129
- } = _ref;
130
- if (!online) {
131
- dispatch(InputAction.NETWORK_CHANGE, {});
132
- }
133
- });
134
120
  const hasMore = attachmentOptions.image || attachmentOptions.video;
135
121
  const isMore = !text.trim().length && hasMore;
136
122
  const send = async inputBlocks => {
@@ -165,19 +151,19 @@ export default function MessageInputAIStream(props) {
165
151
  }
166
152
  }
167
153
  };
168
- useOnEvent('sendMessage', async _ref2 => {
154
+ useOnEvent('sendMessage', async _ref => {
169
155
  let {
170
156
  blocks
171
- } = _ref2;
157
+ } = _ref;
172
158
  if (uploading) {
173
159
  return;
174
160
  }
175
161
  send(blocks);
176
162
  });
177
- useOnEvent('setInputBlocks', async _ref3 => {
163
+ useOnEvent('setInputBlocks', async _ref2 => {
178
164
  let {
179
165
  blocks
180
- } = _ref3;
166
+ } = _ref2;
181
167
  if (uploading || state.current !== InputState.PENDING) {
182
168
  return;
183
169
  }
@@ -304,6 +290,12 @@ export default function MessageInputAIStream(props) {
304
290
  const emitter = new Emitter();
305
291
  emitter.addEventListener('error', async error => {
306
292
  logger.error('MessageInputAIStream', 'AsrInput error', error);
293
+ if (state.current === InputState.RECORDING) {
294
+ clearTimeout(state.payload.recordTimeOutId);
295
+ }
296
+ if (state.current === InputState.RESPONDING) {
297
+ return;
298
+ }
307
299
  if (dispatch(InputAction.ASR_ERROR, {})) {
308
300
  var _error$detail;
309
301
  if (((_error$detail = error.detail) === null || _error$detail === void 0 ? void 0 : _error$detail.name) === 'AsrEmptyError') {
@@ -382,7 +374,7 @@ export default function MessageInputAIStream(props) {
382
374
  onConfirm: async () => {
383
375
  logger.debug('MessageInputAIStream', 'AsrInput onConfirm');
384
376
  recordingFlagRef.current = false;
385
- if (state.current === InputState.ABORTING) {
377
+ if (state.current === InputState.ABORTING || state.current === InputState.PENDING) {
386
378
  return;
387
379
  }
388
380
  const payload = state.payload;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/t-agent-ui-ray",
3
- "version": "0.2.0-beta-13",
3
+ "version": "0.2.0-beta-15",
4
4
  "author": "Tuya.inc",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -40,5 +40,5 @@
40
40
  "@types/echarts": "^4.9.22",
41
41
  "@types/markdown-it": "^14.1.1"
42
42
  },
43
- "gitHead": "ad4d4b4637a4a5396bcf5adf21adcbf215561436"
43
+ "gitHead": "f6fabb33ac8ef9cb264fbde8bec12dacc1d63ed7"
44
44
  }