@ray-js/t-agent-ui-ray 0.2.0-beta-10 → 0.2.0-beta-11

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.
@@ -12,6 +12,7 @@ import { Emitter, EmitterEvent } from '@ray-js/t-agent';
12
12
  import cx from 'clsx';
13
13
  import imageSvg from '../icons/image.svg';
14
14
  import videoSvg from '../icons/video.svg';
15
+ import cameraSvg from '../icons/camera.svg';
15
16
  import { useAttachmentInput, useChatAgent, useEmitEvent, useIsUnmounted, useOnEvent, useTranslate } from '../../hooks';
16
17
  import AsrInput from './AsrInput';
17
18
  import { useSleep } from '../../hooks/useSleep';
@@ -389,7 +390,7 @@ export default function MessageInputAIStream(props) {
389
390
  });
390
391
  return;
391
392
  }
392
- await upload('image', 1);
393
+ await upload('album', 1);
393
394
  } catch (e) {
394
395
  ty.showToast({
395
396
  icon: 'error',
@@ -401,6 +402,29 @@ export default function MessageInputAIStream(props) {
401
402
  className: "t-agent-message-input-panel-button-icon"
402
403
  }, /*#__PURE__*/React.createElement(Image, {
403
404
  src: imageSvg
405
+ }))), attachmentOptions.image && /*#__PURE__*/React.createElement(Button, {
406
+ className: "t-agent-message-input-panel-button",
407
+ onClick: async () => {
408
+ try {
409
+ if (uploaded.filter(f => f.type === 'image').length >= (attachmentOptions.imageCount || 1)) {
410
+ ty.showToast({
411
+ icon: 'none',
412
+ title: t('t-agent.input.upload.image.max-reached')
413
+ });
414
+ return;
415
+ }
416
+ await upload('camera', 1);
417
+ } catch (e) {
418
+ ty.showToast({
419
+ icon: 'error',
420
+ title: t('t-agent.input.upload.failed')
421
+ });
422
+ }
423
+ }
424
+ }, /*#__PURE__*/React.createElement(View, {
425
+ className: "t-agent-message-input-panel-button-icon"
426
+ }, /*#__PURE__*/React.createElement(Image, {
427
+ src: cameraSvg
404
428
  }))), attachmentOptions.video && /*#__PURE__*/React.createElement(Button, {
405
429
  className: "t-agent-message-input-panel-button",
406
430
  onClick: async () => {
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill="none" version="1.1" width="20" height="18" viewBox="0 0 20 18"><g><path d="M7.82843,2L5.82843,4L2,4L2,16L18,16L18,4L14.1716,4L12.1716,2L7.82843,2ZM7,0L13,0L15,2L19,2C19.5523,2,20,2.44772,20,3L20,17C20,17.5523,19.5523,18,19,18L1,18C0.44772,18,0,17.5523,0,17L0,3C0,2.44772,0.44772,2,1,2L5,2L7,0ZM10,15C6.96243,15,4.5,12.5376,4.5,9.5C4.5,6.46243,6.96243,4,10,4C13.0376,4,15.5,6.46243,15.5,9.5C15.5,12.5376,13.0376,15,10,15ZM10,13C11.933,13,13.5,11.433,13.5,9.5C13.5,7.567,11.933,6,10,6C8.067,6,6.5,7.567,6.5,9.5C6.5,11.433,8.067,13,10,13Z" fill="#3D3D3D" fill-opacity="1"/></g></svg>
@@ -18,5 +18,5 @@ export declare function useAttachmentInput({ local }?: {
18
18
  setUploaded: import("react").Dispatch<import("react").SetStateAction<UploadFile[]>>;
19
19
  uploading: boolean;
20
20
  loadBlocks: (blocks: InputBlock[], append?: boolean) => void;
21
- upload: (type: 'image' | 'video', count?: any) => Promise<void>;
21
+ upload: (type: 'image' | 'video' | 'camera' | 'album', count?: any) => Promise<void>;
22
22
  };
@@ -109,47 +109,80 @@ export function useAttachmentInput() {
109
109
  } = useRenderOptions();
110
110
  const upload = useCallback(async function (type) {
111
111
  let count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
112
- if (type === 'image') {
112
+ if (type === 'image' || type === 'camera' || type === 'album') {
113
113
  let file = [];
114
- try {
115
- const sourceType = await new Promise(resolve => {
116
- ty.showActionSheet({
117
- itemList: [t('t-agent.input.upload.source-type.camera'), t('t-agent.input.upload.source-type.album')],
118
- success: _ref => {
119
- let {
120
- tapIndex
121
- } = _ref;
122
- if (tapIndex === 0) {
123
- ty.authorize({
124
- scope: 'scope.camera',
125
- success() {
126
- resolve('camera');
127
- },
128
- fail() {
129
- ty.showToast({
130
- title: t('t-agent.input.upload.source-type.camera.require-permission'),
131
- icon: 'none'
132
- });
133
- resolve('');
134
- }
135
- });
136
- } else if (tapIndex === 1) {
137
- resolve('album');
138
- } else {
114
+ if (type === 'image') {
115
+ try {
116
+ const sourceType = await new Promise(resolve => {
117
+ ty.showActionSheet({
118
+ itemList: [t('t-agent.input.upload.source-type.camera'), t('t-agent.input.upload.source-type.album')],
119
+ success: _ref => {
120
+ let {
121
+ tapIndex
122
+ } = _ref;
123
+ if (tapIndex === 0) {
124
+ ty.authorize({
125
+ scope: 'scope.camera',
126
+ success() {
127
+ resolve('camera');
128
+ },
129
+ fail() {
130
+ ty.showToast({
131
+ title: t('t-agent.input.upload.source-type.camera.require-permission'),
132
+ icon: 'none'
133
+ });
134
+ resolve('');
135
+ }
136
+ });
137
+ } else if (tapIndex === 1) {
138
+ resolve('album');
139
+ } else {
140
+ resolve('');
141
+ }
142
+ },
143
+ fail() {
139
144
  resolve('');
140
145
  }
141
- },
142
- fail() {
143
- resolve('');
144
- }
146
+ });
145
147
  });
146
- });
147
- if (!sourceType) {
148
+ if (!sourceType) {
149
+ return;
150
+ }
151
+ file = await chooseImage(count, sourceType);
152
+ } catch (err) {
153
+ return;
154
+ }
155
+ }
156
+ if (type === 'camera') {
157
+ try {
158
+ const allowUseCamera = await new Promise(resolve => {
159
+ ty.authorize({
160
+ scope: 'scope.camera',
161
+ success() {
162
+ resolve(true);
163
+ },
164
+ fail() {
165
+ ty.showToast({
166
+ title: t('t-agent.input.upload.source-type.camera.require-permission'),
167
+ icon: 'none'
168
+ });
169
+ resolve(false);
170
+ }
171
+ });
172
+ });
173
+ if (allowUseCamera) {
174
+ file = await chooseImage(count, 'camera');
175
+ }
176
+ } catch (err) {
177
+ return;
178
+ }
179
+ }
180
+ if (type === 'album') {
181
+ try {
182
+ file = await chooseImage(count, 'album');
183
+ } catch (err) {
148
184
  return;
149
185
  }
150
- file = await chooseImage(count, sourceType);
151
- } catch (err) {
152
- return;
153
186
  }
154
187
  await Promise.all(file.map(async _ref2 => {
155
188
  let {
@@ -49,6 +49,7 @@
49
49
  display: -webkit-box;
50
50
  -webkit-line-clamp: 2; /* 控制显示行数 */
51
51
  -webkit-box-orient: vertical;
52
+ line-height: 33rpx;
52
53
  height: 66rpx;
53
54
 
54
55
 
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-10",
3
+ "version": "0.2.0-beta-11",
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": "a17ba630a9ec71afe6a0fc46c427f664d46acf82"
43
+ "gitHead": "dd56b31b0095fb82d0fb5d4f58581d00ae2970ee"
44
44
  }