@ray-js/t-agent-ui-ray 0.1.1 → 0.2.0-beta-2
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.js +0 -10
- package/dist/MessageInput/MessageInputAIStream/AsrInput.d.ts +15 -0
- package/dist/MessageInput/MessageInputAIStream/AsrInput.js +112 -0
- package/dist/MessageInput/MessageInputAIStream/index.d.ts +10 -0
- package/dist/MessageInput/MessageInputAIStream/index.js +360 -0
- package/dist/MessageInput/{AsrInput.d.ts → MessageInputAssistant/AsrInput.d.ts} +1 -1
- package/dist/MessageInput/{AsrInput.js → MessageInputAssistant/AsrInput.js} +2 -2
- package/dist/MessageInput/MessageInputAssistant/index.d.ts +11 -0
- package/dist/MessageInput/MessageInputAssistant/index.js +322 -0
- package/dist/{hooks → MessageInput/MessageInputAssistant}/useAsrInput.js +1 -1
- package/dist/MessageInput/icons/keyboard.svg +1 -0
- package/dist/MessageInput/index.d.ts +0 -1
- package/dist/MessageInput/index.js +3 -320
- package/dist/MessageInput/index.less +83 -3
- package/dist/MessageList/index.d.ts +5 -0
- package/dist/MessageList/index.js +4 -2
- package/dist/MessageRender/index.d.ts +6 -1
- package/dist/MessageRender/index.js +19 -2
- package/dist/MessageRender/index.less +48 -1
- package/dist/PrivateImage/index.js +1 -1
- package/dist/cards/WorkflowReplyCard/index.d.ts +11 -1
- package/dist/cards/WorkflowReplyCard/index.js +7 -1
- package/dist/cards/map.js +3 -2
- package/dist/contexts.d.ts +1 -2
- package/dist/contexts.js +1 -0
- package/dist/hooks/context.d.ts +3 -3
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +2 -2
- package/dist/hooks/useAttachmentInput.d.ts +3 -1
- package/dist/hooks/useAttachmentInput.js +75 -34
- package/dist/hooks/useLongPress.d.ts +1 -1
- package/dist/hooks/useLongPress.js +38 -36
- package/dist/hooks/useMultSelect.d.ts +7 -0
- package/dist/hooks/useMultSelect.js +12 -0
- package/dist/i18n/strings.d.ts +8 -0
- package/dist/i18n/strings.js +11 -0
- package/dist/renderOption.js +5 -0
- package/dist/tiles/BubbleTile/index.js +9 -10
- package/dist/tiles/CardTile/index.js +6 -7
- package/dist/tiles/ExecuteCardTile/index.d.ts +8 -1
- package/dist/tiles/ExecuteCardTile/index.js +11 -1
- package/dist/tiles/FileTile/index.d.ts +8 -0
- package/dist/tiles/FileTile/index.js +57 -0
- package/dist/tiles/FileTile/index.less +44 -0
- package/dist/tiles/ImageTile/index.js +1 -0
- package/dist/tiles/OperateCardTile/Expand.d.ts +7 -1
- package/dist/tiles/OperateCardTile/Expand.js +11 -1
- package/dist/tiles/OperateCardTile/index.d.ts +4 -1
- package/dist/tiles/OperateCardTile/index.js +2 -0
- package/dist/tiles/WorkflowTile/RollBack/index.js +11 -12
- package/dist/tiles/WorkflowTile/index.d.ts +4 -1
- package/dist/tiles/map.js +3 -1
- package/dist/types.d.ts +42 -1
- package/dist/utils/file.d.ts +24 -0
- package/dist/utils/file.js +190 -0
- package/package.json +3 -4
- /package/dist/{hooks → MessageInput/MessageInputAssistant}/useAsrInput.d.ts +0 -0
|
@@ -6,7 +6,6 @@ import "core-js/modules/web.dom-collections.iterator.js";
|
|
|
6
6
|
import './index.less';
|
|
7
7
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
8
8
|
import { View } from '@ray-js/components';
|
|
9
|
-
import { SocketStatus } from '@ray-js/t-agent-plugin-assistant';
|
|
10
9
|
import cx from 'clsx';
|
|
11
10
|
import { ChatAgentContext, MessageContext, RenderContext } from '../contexts';
|
|
12
11
|
import { defaultRenderOptions } from '../renderOption';
|
|
@@ -26,9 +25,6 @@ export default function ChatContainer(props) {
|
|
|
26
25
|
if (!agent.plugins.ui) {
|
|
27
26
|
throw new Error('UI plugin not found');
|
|
28
27
|
}
|
|
29
|
-
if (!agent.plugins.assistant) {
|
|
30
|
-
throw new Error('Assistant plugin not found');
|
|
31
|
-
}
|
|
32
28
|
return agent;
|
|
33
29
|
});
|
|
34
30
|
if (props.agentRef) {
|
|
@@ -59,11 +55,6 @@ export default function ChatContainer(props) {
|
|
|
59
55
|
onEvent,
|
|
60
56
|
emitEvent
|
|
61
57
|
} = agent.plugins.ui;
|
|
62
|
-
const offSocketStatusChange = agent.plugins.assistant.onSocketStatusChange(status => {
|
|
63
|
-
emitEvent('networkChange', {
|
|
64
|
-
online: status === SocketStatus.SUCCESS
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
58
|
const offMessageListInit = onEvent('messageListInit', _ref => {
|
|
68
59
|
let {
|
|
69
60
|
messages
|
|
@@ -113,7 +104,6 @@ export default function ChatContainer(props) {
|
|
|
113
104
|
}
|
|
114
105
|
});
|
|
115
106
|
return () => {
|
|
116
|
-
offSocketStatusChange();
|
|
117
107
|
offMessageListInit();
|
|
118
108
|
offMessageChange();
|
|
119
109
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare const WaveformVisualizer: ({ amplitudeCount }: {
|
|
3
|
+
amplitudeCount: number;
|
|
4
|
+
}) => React.JSX.Element;
|
|
5
|
+
interface IProps {
|
|
6
|
+
amplitudeCount: number;
|
|
7
|
+
recording: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
onConfirm: () => void;
|
|
10
|
+
onRecord: () => void;
|
|
11
|
+
onCancel: () => void;
|
|
12
|
+
onBack: () => void;
|
|
13
|
+
}
|
|
14
|
+
declare const AsrInput: (props: IProps) => React.JSX.Element;
|
|
15
|
+
export default AsrInput;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
2
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
3
|
+
import "core-js/modules/esnext.iterator.map.js";
|
|
4
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
5
|
+
import React, { useState } from 'react';
|
|
6
|
+
import { Button, View } from '@ray-js/ray';
|
|
7
|
+
import cx from 'clsx';
|
|
8
|
+
import { useOnEvent, useTranslate } from '../../hooks';
|
|
9
|
+
export const WaveformVisualizer = _ref => {
|
|
10
|
+
let {
|
|
11
|
+
amplitudeCount
|
|
12
|
+
} = _ref;
|
|
13
|
+
const [bars, setBars] = useState(() => Array.from({
|
|
14
|
+
length: amplitudeCount
|
|
15
|
+
}, (_, index) => /*#__PURE__*/React.createElement(View
|
|
16
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
17
|
+
, {
|
|
18
|
+
key: "asr_wave_".concat(index),
|
|
19
|
+
className: "t-agent-message-input-waveform-bar",
|
|
20
|
+
style: {
|
|
21
|
+
height: 0,
|
|
22
|
+
// 添加渐变色偏移效果
|
|
23
|
+
animationDelay: "".concat(index * 10, "ms")
|
|
24
|
+
}
|
|
25
|
+
})));
|
|
26
|
+
useOnEvent('amplitudes', val => {
|
|
27
|
+
const waveBase = val.body.amplitudes || [];
|
|
28
|
+
const bars = waveBase.map((item, index) => {
|
|
29
|
+
const value = item > 1 ? 1 : item * 100;
|
|
30
|
+
// 将数值映射到高度范围(0-100 → 2px-20px)
|
|
31
|
+
// const height = 2 + (value / 100) * 18;
|
|
32
|
+
return /*#__PURE__*/React.createElement(View
|
|
33
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
34
|
+
, {
|
|
35
|
+
key: "asr_wave_".concat(index),
|
|
36
|
+
className: "t-agent-message-input-waveform-bar t-agent-item",
|
|
37
|
+
style: {
|
|
38
|
+
height: "".concat(value, "%"),
|
|
39
|
+
// 添加渐变色偏移效果
|
|
40
|
+
animationDelay: "".concat(index * 10, "ms")
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
setBars(bars);
|
|
45
|
+
});
|
|
46
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
47
|
+
className: "t-agent-message-input-waveform-container"
|
|
48
|
+
}, bars);
|
|
49
|
+
};
|
|
50
|
+
const AsrInput = props => {
|
|
51
|
+
const [asrElementBounds, setAsrElementBounds] = useState(null);
|
|
52
|
+
const t = useTranslate();
|
|
53
|
+
const [ptt, setPtt] = useState(false);
|
|
54
|
+
const onVoiceTouchEnd = e => {
|
|
55
|
+
const touch = e.origin.changedTouches[0];
|
|
56
|
+
const touchY = touch.clientY;
|
|
57
|
+
setPtt(false);
|
|
58
|
+
// 误触状态
|
|
59
|
+
if (!asrElementBounds) {
|
|
60
|
+
setTimeout(() => {
|
|
61
|
+
props.onCancel();
|
|
62
|
+
}, 200);
|
|
63
|
+
setAsrElementBounds(null);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
// 上滑取消
|
|
67
|
+
if (touchY < asrElementBounds.top - 100) {
|
|
68
|
+
setTimeout(() => {
|
|
69
|
+
props.onCancel();
|
|
70
|
+
}, 200);
|
|
71
|
+
setAsrElementBounds(null);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
setTimeout(() => {
|
|
75
|
+
props.onConfirm();
|
|
76
|
+
}, 200);
|
|
77
|
+
setAsrElementBounds(null);
|
|
78
|
+
};
|
|
79
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(View, {
|
|
80
|
+
className: cx('t-agent-message-input-ptt', {
|
|
81
|
+
't-agent-message-input-ptt-handle': ptt
|
|
82
|
+
}),
|
|
83
|
+
onTouchStart: () => {
|
|
84
|
+
const query = ty.createSelectorQuery();
|
|
85
|
+
query.select('.t-agent-message-input-ptt').boundingClientRect(rect => {
|
|
86
|
+
if (!rect) return;
|
|
87
|
+
setAsrElementBounds(rect);
|
|
88
|
+
}).exec();
|
|
89
|
+
setPtt(true);
|
|
90
|
+
setTimeout(() => {
|
|
91
|
+
props.onRecord();
|
|
92
|
+
}, 200);
|
|
93
|
+
},
|
|
94
|
+
onTouchCancel: onVoiceTouchEnd,
|
|
95
|
+
onTouchEnd: onVoiceTouchEnd
|
|
96
|
+
}, props.recording ? /*#__PURE__*/React.createElement(View, {
|
|
97
|
+
className: "t-agent-message-input-oninput"
|
|
98
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
99
|
+
className: "t-agent-message-input-oninput-text-top"
|
|
100
|
+
}, t('t-agent.input.asr.oninput.text.top')), /*#__PURE__*/React.createElement(View, {
|
|
101
|
+
className: "t-agent-message-input-oninput-text-center"
|
|
102
|
+
}, t('t-agent.input.asr.oninput.text.center')), /*#__PURE__*/React.createElement(WaveformVisualizer, {
|
|
103
|
+
amplitudeCount: props.amplitudeCount
|
|
104
|
+
})) : /*#__PURE__*/React.createElement(View, {
|
|
105
|
+
className: "t-agent-message-input-ptt-text"
|
|
106
|
+
}, " ", t('t-agent.input.asr.ptt'))), !props.recording && /*#__PURE__*/React.createElement(Button, {
|
|
107
|
+
className: "t-agent-message-input-button t-agent-message-input-button-keyboard",
|
|
108
|
+
"data-testid": "t-agent-message-input-button-asr",
|
|
109
|
+
onClick: props.onBack
|
|
110
|
+
}));
|
|
111
|
+
};
|
|
112
|
+
export default AsrInput;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import '../index.less';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
interface Props {
|
|
4
|
+
className?: string;
|
|
5
|
+
renderTop?: React.ReactNode;
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
style?: React.CSSProperties;
|
|
8
|
+
}
|
|
9
|
+
export default function MessageInputAIStream(props: Props): React.JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import "core-js/modules/es.string.trim.js";
|
|
2
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
3
|
+
import "core-js/modules/esnext.iterator.filter.js";
|
|
4
|
+
import "core-js/modules/esnext.iterator.map.js";
|
|
5
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
6
|
+
import '../index.less';
|
|
7
|
+
import { Button, View } from '@ray-js/components';
|
|
8
|
+
import React, { useRef, useState } from 'react';
|
|
9
|
+
import { Image, Input, ScrollView } from '@ray-js/ray';
|
|
10
|
+
import { AbortController, authorize } from '@ray-js/t-agent-plugin-aistream';
|
|
11
|
+
import { Emitter, EmitterEvent } from '@ray-js/t-agent';
|
|
12
|
+
import cx from 'clsx';
|
|
13
|
+
import imageSvg from '../icons/image.svg';
|
|
14
|
+
import videoSvg from '../icons/video.svg';
|
|
15
|
+
import loadingSvg from '../icons/loading.svg';
|
|
16
|
+
import closeCircleSvg from '../icons/close-circle.svg';
|
|
17
|
+
import { useAttachmentInput, useChatAgent, useEmitEvent, useIsUnmounted, useOnEvent, useTranslate } from '../../hooks';
|
|
18
|
+
import AsrInput from './AsrInput';
|
|
19
|
+
const AMPLITUDE_COUNT = 60;
|
|
20
|
+
export default function MessageInputAIStream(props) {
|
|
21
|
+
const [moreOpen, setMoreOpen] = useState(false);
|
|
22
|
+
const t = useTranslate();
|
|
23
|
+
const [text, setText] = useState('');
|
|
24
|
+
const [record, setRecord] = useState({
|
|
25
|
+
startAt: 0,
|
|
26
|
+
recording: false,
|
|
27
|
+
confirm: null,
|
|
28
|
+
cancel: null
|
|
29
|
+
});
|
|
30
|
+
const attachmentInput = useAttachmentInput({
|
|
31
|
+
local: true
|
|
32
|
+
});
|
|
33
|
+
const {
|
|
34
|
+
uploading,
|
|
35
|
+
uploaded,
|
|
36
|
+
setUploaded,
|
|
37
|
+
upload
|
|
38
|
+
} = attachmentInput;
|
|
39
|
+
const acRef = useRef(null);
|
|
40
|
+
const [responding, setResponding] = useState(false);
|
|
41
|
+
const [mode, setMode] = useState('text');
|
|
42
|
+
const agent = useChatAgent();
|
|
43
|
+
const emitEvent = useEmitEvent();
|
|
44
|
+
const isUnmounted = useIsUnmounted();
|
|
45
|
+
useOnEvent('networkChange', _ref => {
|
|
46
|
+
let {
|
|
47
|
+
online
|
|
48
|
+
} = _ref;
|
|
49
|
+
if (!online && responding) {
|
|
50
|
+
setResponding(false);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const isMore = !text.trim().length && true;
|
|
54
|
+
const send = async inputBlocks => {
|
|
55
|
+
if (!(inputBlocks !== null && inputBlocks !== void 0 && inputBlocks.length) || attachmentInput.uploading || responding) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
setUploaded([]);
|
|
59
|
+
setText('');
|
|
60
|
+
setResponding(true);
|
|
61
|
+
const ac = new AbortController();
|
|
62
|
+
acRef.current = ac;
|
|
63
|
+
ac.signal.addEventListener('abort', () => {
|
|
64
|
+
if (acRef.current === ac) {
|
|
65
|
+
acRef.current = null;
|
|
66
|
+
}
|
|
67
|
+
setResponding(false);
|
|
68
|
+
});
|
|
69
|
+
try {
|
|
70
|
+
await agent.pushInputBlocks(inputBlocks, ac.signal);
|
|
71
|
+
} finally {
|
|
72
|
+
if (!isUnmounted()) {
|
|
73
|
+
setResponding(false);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
useOnEvent('sendMessage', async _ref2 => {
|
|
78
|
+
let {
|
|
79
|
+
blocks
|
|
80
|
+
} = _ref2;
|
|
81
|
+
if (uploading || responding) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
setText('');
|
|
85
|
+
setMoreOpen(false);
|
|
86
|
+
setUploaded([]);
|
|
87
|
+
setResponding(true);
|
|
88
|
+
const ac = new AbortController();
|
|
89
|
+
acRef.current = ac;
|
|
90
|
+
ac.signal.addEventListener('abort', () => {
|
|
91
|
+
if (acRef.current === ac) {
|
|
92
|
+
acRef.current = null;
|
|
93
|
+
}
|
|
94
|
+
setResponding(false);
|
|
95
|
+
});
|
|
96
|
+
try {
|
|
97
|
+
await agent.pushInputBlocks(blocks, ac.signal);
|
|
98
|
+
} finally {
|
|
99
|
+
if (!isUnmounted()) {
|
|
100
|
+
setResponding(false);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
useOnEvent('setInputBlocks', async _ref3 => {
|
|
105
|
+
let {
|
|
106
|
+
blocks
|
|
107
|
+
} = _ref3;
|
|
108
|
+
if (uploading || responding) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (mode !== 'text') {
|
|
112
|
+
setMode('text');
|
|
113
|
+
}
|
|
114
|
+
attachmentInput.loadBlocks(blocks);
|
|
115
|
+
let t = '';
|
|
116
|
+
for (const block of blocks) {
|
|
117
|
+
if (block.type === 'text') {
|
|
118
|
+
t = block.text;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (t) {
|
|
122
|
+
setText(t);
|
|
123
|
+
}
|
|
124
|
+
setMoreOpen(false);
|
|
125
|
+
});
|
|
126
|
+
const openMoreClick = () => {
|
|
127
|
+
setMoreOpen(!moreOpen);
|
|
128
|
+
if (!moreOpen) {
|
|
129
|
+
emitEvent('scrollToBottom', {
|
|
130
|
+
animation: true
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
let container;
|
|
135
|
+
if (mode === 'text') {
|
|
136
|
+
container = /*#__PURE__*/React.createElement(View, {
|
|
137
|
+
className: "t-agent-message-input-text-bar"
|
|
138
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
139
|
+
className: "t-agent-message-input-text-group"
|
|
140
|
+
}, /*#__PURE__*/React.createElement(Input, {
|
|
141
|
+
confirmType: "send",
|
|
142
|
+
value: text,
|
|
143
|
+
onInput: event => setText(event.detail.value),
|
|
144
|
+
placeholder: props.placeholder,
|
|
145
|
+
"data-testid": "t-agent-message-input-text-inner",
|
|
146
|
+
className: "t-agent-message-input-text-inner",
|
|
147
|
+
onConfirm: () => {
|
|
148
|
+
if (text.trim().length) {
|
|
149
|
+
send([...attachmentInput.blocks, {
|
|
150
|
+
type: 'text',
|
|
151
|
+
text
|
|
152
|
+
}]);
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
maxLength: 200,
|
|
156
|
+
placeholderStyle: "color: var(--app-B1-N4)",
|
|
157
|
+
onFocus: () => {
|
|
158
|
+
setMoreOpen(false);
|
|
159
|
+
emitEvent('scrollToBottom', {
|
|
160
|
+
animation: true
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}), /*#__PURE__*/React.createElement(Button, {
|
|
164
|
+
"data-testid": "t-agent-message-input-button-asr",
|
|
165
|
+
onClick: async () => {
|
|
166
|
+
const auth = await authorize({
|
|
167
|
+
scope: 'scope.record'
|
|
168
|
+
}).then(() => true, () => false);
|
|
169
|
+
if (!auth) {
|
|
170
|
+
ty.showToast({
|
|
171
|
+
icon: 'none',
|
|
172
|
+
title: t('t-agent.input.voice.require-permission')
|
|
173
|
+
});
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
setText('');
|
|
177
|
+
setMode('voice');
|
|
178
|
+
},
|
|
179
|
+
className: "t-agent-message-input-button t-agent-message-input-button-voice"
|
|
180
|
+
})), /*#__PURE__*/React.createElement(Button, {
|
|
181
|
+
disabled: !isMore && uploading,
|
|
182
|
+
className: cx('t-agent-message-input-button', {
|
|
183
|
+
't-agent-message-input-button-more': isMore,
|
|
184
|
+
't-agent-message-input-button-more-open': moreOpen && isMore,
|
|
185
|
+
't-agent-message-input-button-send': !isMore && !responding,
|
|
186
|
+
't-agent-message-input-button-stop': responding
|
|
187
|
+
}),
|
|
188
|
+
"data-testid": "t-agent-message-input-button-main",
|
|
189
|
+
onClick: async () => {
|
|
190
|
+
if (responding) {
|
|
191
|
+
if (acRef.current) {
|
|
192
|
+
acRef.current.abort('User abort');
|
|
193
|
+
}
|
|
194
|
+
} else if (isMore) {
|
|
195
|
+
openMoreClick();
|
|
196
|
+
} else if (text.trim().length) {
|
|
197
|
+
await send([...attachmentInput.blocks, {
|
|
198
|
+
type: 'text',
|
|
199
|
+
text
|
|
200
|
+
}]);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}));
|
|
204
|
+
} else {
|
|
205
|
+
container = /*#__PURE__*/React.createElement(View, {
|
|
206
|
+
className: "t-agent-message-input-text-bar"
|
|
207
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
208
|
+
className: "t-agent-message-input-text-group"
|
|
209
|
+
}, /*#__PURE__*/React.createElement(AsrInput, {
|
|
210
|
+
disabled: responding,
|
|
211
|
+
amplitudeCount: AMPLITUDE_COUNT,
|
|
212
|
+
recording: record.recording,
|
|
213
|
+
onRecord: async () => {
|
|
214
|
+
const emitter = new Emitter();
|
|
215
|
+
setRecord({
|
|
216
|
+
startAt: Date.now(),
|
|
217
|
+
recording: true,
|
|
218
|
+
confirm: () => {
|
|
219
|
+
console.log('setRecord confirm');
|
|
220
|
+
emitter.dispatchEvent(new EmitterEvent('confirm'));
|
|
221
|
+
setRecord({
|
|
222
|
+
startAt: 0,
|
|
223
|
+
recording: false,
|
|
224
|
+
confirm: null,
|
|
225
|
+
cancel: null
|
|
226
|
+
});
|
|
227
|
+
},
|
|
228
|
+
cancel: () => {
|
|
229
|
+
console.log('setRecord cancel');
|
|
230
|
+
emitter.dispatchEvent(new EmitterEvent('cancel'));
|
|
231
|
+
setRecord({
|
|
232
|
+
startAt: 0,
|
|
233
|
+
recording: false,
|
|
234
|
+
confirm: null,
|
|
235
|
+
cancel: null
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
emitter.addEventListener('error', event => {
|
|
240
|
+
console.log('setRecord error');
|
|
241
|
+
ty.showToast({
|
|
242
|
+
icon: 'error',
|
|
243
|
+
title: t('t-agent.input.voice.recording-failed')
|
|
244
|
+
});
|
|
245
|
+
console.error(event);
|
|
246
|
+
setRecord({
|
|
247
|
+
startAt: 0,
|
|
248
|
+
recording: false,
|
|
249
|
+
confirm: null,
|
|
250
|
+
cancel: null
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
console.log('setRecord send');
|
|
254
|
+
await send([...attachmentInput.blocks, {
|
|
255
|
+
type: 'audio',
|
|
256
|
+
audio_emitter: emitter,
|
|
257
|
+
amplitude_count: AMPLITUDE_COUNT
|
|
258
|
+
}]);
|
|
259
|
+
},
|
|
260
|
+
onConfirm: () => {
|
|
261
|
+
var _record$confirm;
|
|
262
|
+
console.log('test onConfirm');
|
|
263
|
+
(_record$confirm = record.confirm) === null || _record$confirm === void 0 || _record$confirm.call(record);
|
|
264
|
+
},
|
|
265
|
+
onCancel: () => {
|
|
266
|
+
var _record$cancel;
|
|
267
|
+
console.log('test onCancel');
|
|
268
|
+
(_record$cancel = record.cancel) === null || _record$cancel === void 0 || _record$cancel.call(record);
|
|
269
|
+
},
|
|
270
|
+
onBack: () => setMode('text')
|
|
271
|
+
})));
|
|
272
|
+
}
|
|
273
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
274
|
+
className: "".concat(props.className || '', " t-agent-message-input"),
|
|
275
|
+
style: props.style
|
|
276
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
277
|
+
className: "t-agent-message-input-container"
|
|
278
|
+
}, props.renderTop, !!uploaded.length && /*#__PURE__*/React.createElement(ScrollView, {
|
|
279
|
+
scrollX: true,
|
|
280
|
+
scrollY: false,
|
|
281
|
+
enableFlex: true,
|
|
282
|
+
className: "t-agent-message-input-uploaded-files",
|
|
283
|
+
refresherTriggered: false
|
|
284
|
+
}, uploaded.map(file => {
|
|
285
|
+
let content;
|
|
286
|
+
switch (file.type) {
|
|
287
|
+
case 'image':
|
|
288
|
+
content = /*#__PURE__*/React.createElement(Image, {
|
|
289
|
+
className: "t-agent-message-input-uploaded-file-image",
|
|
290
|
+
mode: "aspectFill",
|
|
291
|
+
src: file.url
|
|
292
|
+
});
|
|
293
|
+
break;
|
|
294
|
+
case 'video':
|
|
295
|
+
content = /*#__PURE__*/React.createElement(Image, {
|
|
296
|
+
className: "t-agent-message-input-uploaded-file-image",
|
|
297
|
+
mode: "aspectFill",
|
|
298
|
+
src: file.thumbUrl
|
|
299
|
+
});
|
|
300
|
+
break;
|
|
301
|
+
case 'loading':
|
|
302
|
+
content = /*#__PURE__*/React.createElement(View, {
|
|
303
|
+
className: "t-agent-message-input-uploaded-file-loading",
|
|
304
|
+
key: file.id
|
|
305
|
+
}, /*#__PURE__*/React.createElement(Image, {
|
|
306
|
+
src: loadingSvg,
|
|
307
|
+
className: "t-agent-message-input-uploaded-file-loading-icon"
|
|
308
|
+
}));
|
|
309
|
+
break;
|
|
310
|
+
default:
|
|
311
|
+
content = null;
|
|
312
|
+
}
|
|
313
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
314
|
+
key: file.id,
|
|
315
|
+
className: "t-agent-message-input-uploaded-file"
|
|
316
|
+
}, /*#__PURE__*/React.createElement(Image, {
|
|
317
|
+
onClick: () => {
|
|
318
|
+
setUploaded(prev => prev.filter(f => f.id !== file.id));
|
|
319
|
+
},
|
|
320
|
+
className: "t-agent-message-input-uploaded-file-delete",
|
|
321
|
+
src: closeCircleSvg
|
|
322
|
+
}), content);
|
|
323
|
+
})), container), /*#__PURE__*/React.createElement(View, {
|
|
324
|
+
className: "t-agent-message-input-panel ".concat(moreOpen ? '' : 't-agent-message-input-panel-close')
|
|
325
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
326
|
+
className: "t-agent-message-input-panel-content"
|
|
327
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
328
|
+
className: "t-agent-message-input-panel-button",
|
|
329
|
+
onClick: async () => {
|
|
330
|
+
try {
|
|
331
|
+
await upload('image', 1);
|
|
332
|
+
} catch (e) {
|
|
333
|
+
ty.showToast({
|
|
334
|
+
icon: 'error',
|
|
335
|
+
title: t('t-agent.input.upload.failed')
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
340
|
+
className: "t-agent-message-input-panel-button-icon"
|
|
341
|
+
}, /*#__PURE__*/React.createElement(Image, {
|
|
342
|
+
src: imageSvg
|
|
343
|
+
}))), /*#__PURE__*/React.createElement(Button, {
|
|
344
|
+
className: "t-agent-message-input-panel-button",
|
|
345
|
+
onClick: async () => {
|
|
346
|
+
try {
|
|
347
|
+
await upload('video', 1);
|
|
348
|
+
} catch (e) {
|
|
349
|
+
ty.showToast({
|
|
350
|
+
icon: 'error',
|
|
351
|
+
title: t('t-agent.input.upload.failed')
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
356
|
+
className: "t-agent-message-input-panel-button-icon"
|
|
357
|
+
}, /*#__PURE__*/React.createElement(Image, {
|
|
358
|
+
src: videoSvg
|
|
359
|
+
}))))));
|
|
360
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import '
|
|
1
|
+
import '../index.less';
|
|
2
2
|
import { Button, Text, View, Textarea } from '@ray-js/components';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import cx from 'clsx';
|
|
5
|
-
import { useAsrInput } from '
|
|
5
|
+
import { useAsrInput } from './useAsrInput';
|
|
6
6
|
export default function AsrInput(props) {
|
|
7
7
|
const {
|
|
8
8
|
responding,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import '../index.less';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
interface Props {
|
|
4
|
+
className?: string;
|
|
5
|
+
renderTop?: React.ReactNode;
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
style?: React.CSSProperties;
|
|
8
|
+
multiModal?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export default function MessageInputAssistant(props: Props): React.JSX.Element;
|
|
11
|
+
export {};
|