@ray-js/t-agent-ui-ray 0.1.1 → 0.2.0-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.
Files changed (52) hide show
  1. package/dist/ChatContainer/index.js +0 -10
  2. package/dist/MessageInput/MessageInputAIStream/AsrInput.d.ts +15 -0
  3. package/dist/MessageInput/MessageInputAIStream/AsrInput.js +109 -0
  4. package/dist/MessageInput/MessageInputAIStream/index.d.ts +10 -0
  5. package/dist/MessageInput/MessageInputAIStream/index.js +359 -0
  6. package/dist/MessageInput/{AsrInput.d.ts → MessageInputAssistant/AsrInput.d.ts} +1 -1
  7. package/dist/MessageInput/{AsrInput.js → MessageInputAssistant/AsrInput.js} +2 -2
  8. package/dist/MessageInput/MessageInputAssistant/index.d.ts +11 -0
  9. package/dist/MessageInput/MessageInputAssistant/index.js +322 -0
  10. package/dist/MessageInput/icons/keyboard.svg +1 -0
  11. package/dist/MessageInput/index.d.ts +0 -1
  12. package/dist/MessageInput/index.js +3 -320
  13. package/dist/MessageInput/index.less +78 -3
  14. package/dist/MessageList/index.d.ts +5 -0
  15. package/dist/MessageList/index.js +4 -2
  16. package/dist/MessageRender/index.d.ts +6 -1
  17. package/dist/MessageRender/index.js +19 -2
  18. package/dist/MessageRender/index.less +48 -1
  19. package/dist/PrivateImage/index.js +1 -1
  20. package/dist/cards/map.js +3 -2
  21. package/dist/contexts.d.ts +1 -2
  22. package/dist/contexts.js +1 -0
  23. package/dist/hooks/index.d.ts +1 -0
  24. package/dist/hooks/index.js +2 -1
  25. package/dist/hooks/useAttachmentInput.d.ts +3 -1
  26. package/dist/hooks/useAttachmentInput.js +75 -34
  27. package/dist/hooks/useLongPress.d.ts +1 -1
  28. package/dist/hooks/useLongPress.js +38 -36
  29. package/dist/hooks/useMultSelect.d.ts +7 -0
  30. package/dist/hooks/useMultSelect.js +12 -0
  31. package/dist/i18n/strings.d.ts +8 -0
  32. package/dist/i18n/strings.js +11 -0
  33. package/dist/renderOption.js +5 -0
  34. package/dist/tiles/BubbleTile/index.js +9 -10
  35. package/dist/tiles/CardTile/index.js +6 -7
  36. package/dist/tiles/ExecuteCardTile/index.d.ts +8 -1
  37. package/dist/tiles/ExecuteCardTile/index.js +11 -1
  38. package/dist/tiles/FileTile/index.d.ts +8 -0
  39. package/dist/tiles/FileTile/index.js +57 -0
  40. package/dist/tiles/FileTile/index.less +44 -0
  41. package/dist/tiles/ImageTile/index.js +1 -0
  42. package/dist/tiles/OperateCardTile/Expand.d.ts +7 -1
  43. package/dist/tiles/OperateCardTile/Expand.js +11 -1
  44. package/dist/tiles/OperateCardTile/index.d.ts +4 -1
  45. package/dist/tiles/OperateCardTile/index.js +2 -0
  46. package/dist/tiles/WorkflowTile/RollBack/index.js +11 -12
  47. package/dist/tiles/WorkflowTile/index.d.ts +4 -1
  48. package/dist/tiles/map.js +3 -1
  49. package/dist/types.d.ts +2 -0
  50. package/dist/utils/file.d.ts +24 -0
  51. package/dist/utils/file.js +190 -0
  52. package/package.json +2 -2
@@ -8,6 +8,7 @@ export default function ImageTile(props) {
8
8
  const {
9
9
  src
10
10
  } = props.tile.data;
11
+ console.log('props.tile.data', props.tile.data);
11
12
  const {
12
13
  getStaticResourceBizType
13
14
  } = useRenderOptions();
@@ -1,6 +1,12 @@
1
1
  import React from 'react';
2
- import { DeviceInfoItem, SceneInfoItem, ChangeInfoItem } from '@ray-js/t-agent-plugin-assistant';
3
2
  import './Expand.less';
3
+ export declare enum SceneType {
4
+ EXECUTE = 1,
5
+ AUTO = 2
6
+ }
7
+ type DeviceInfoItem = any;
8
+ type SceneInfoItem = any;
9
+ type ChangeInfoItem = any;
4
10
  export interface IOperations {
5
11
  device: DeviceInfoItem[];
6
12
  scene: SceneInfoItem[];
@@ -2,13 +2,23 @@ import "core-js/modules/esnext.iterator.constructor.js";
2
2
  import "core-js/modules/esnext.iterator.map.js";
3
3
  import { View, Text, Image } from '@ray-js/components';
4
4
  import React from 'react';
5
- import { SceneType } from '@ray-js/t-agent-plugin-assistant';
5
+ // import {
6
+ // DeviceInfoItem,
7
+ // SceneInfoItem,
8
+ // ChangeInfoItem,
9
+ // SceneType,
10
+ // } from '@ray-js/t-agent-plugin-assistant';
6
11
  import Tabs from './Tabs';
7
12
  import './Expand.less';
8
13
  import bookmark from '../ExecuteCardTile/bookmark.png';
9
14
  import lockPng from './lock.png';
10
15
  import { useTranslate } from '../../hooks';
11
16
  import { formatMessage } from '../../utils';
17
+ export let SceneType = /*#__PURE__*/function (SceneType) {
18
+ SceneType[SceneType["EXECUTE"] = 1] = "EXECUTE";
19
+ SceneType[SceneType["AUTO"] = 2] = "AUTO";
20
+ return SceneType;
21
+ }({});
12
22
  export default function Expand(_ref) {
13
23
  var _operations$device, _operations$moreDevic, _operations$scene, _operations$moreScene, _operations$more;
14
24
  let {
@@ -1,8 +1,10 @@
1
1
  import React from 'react';
2
2
  import './index.less';
3
- import { ChangeInfoItem, DeviceInfoItem, SceneInfoItem } from '@ray-js/t-agent-plugin-assistant';
4
3
  import { TileProps } from '../../types';
5
4
  import { IOperations } from './Expand';
5
+ type DeviceInfoItem = any;
6
+ type SceneInfoItem = any;
7
+ type ChangeInfoItem = any;
6
8
  export interface OperateCardTileData {
7
9
  deviceInfo: DeviceInfoItem[];
8
10
  sceneInfo: SceneInfoItem[];
@@ -19,3 +21,4 @@ export interface OperateCardTileProps extends TileProps {
19
21
  }) => React.ReactNode;
20
22
  }
21
23
  export default function OperateCardTile(props: OperateCardTileProps): React.JSX.Element | null;
24
+ export {};
@@ -5,6 +5,8 @@ import "core-js/modules/web.dom-collections.iterator.js";
5
5
  import { Text, View } from '@ray-js/components';
6
6
  import React, { useMemo, useState } from 'react';
7
7
  import './index.less';
8
+ // import { ChangeInfoItem, DeviceInfoItem, SceneInfoItem } from '@ray-js/t-agent-plugin-assistant';
9
+
8
10
  import { useTranslate } from '../../hooks';
9
11
  import Expand from './Expand';
10
12
  import { formatMessage } from '../../utils';
@@ -11,19 +11,18 @@ export default function RollBack(props) {
11
11
  return /*#__PURE__*/React.createElement(View, {
12
12
  className: "t-agent-workflow-rollback-tile",
13
13
  onClick: async () => {
14
- const channel = agent.session.get('AIAssistant.channel');
14
+ agent.session.get('AIAssistant.channel');
15
15
  const systemInfo = ty.getSystemInfoSync();
16
- const lang = systemInfo.language;
17
- await agent.plugins.assistant.runSkill('hi', 'assistant', {
18
- channel,
19
- domain: 'control',
20
- intent: 'backNode',
21
- lang,
22
- 'back.node.id': nodeId,
23
- device_id: undefined,
24
- 'text.stream': 'true',
25
- 'tts.disable': 'true'
26
- });
16
+ systemInfo.language; // await agent.plugins.assistant.runSkill('hi', 'assistant', {
17
+ // channel,
18
+ // domain: 'control',
19
+ // intent: 'backNode',
20
+ // lang,
21
+ // 'back.node.id': nodeId,
22
+ // device_id: undefined,
23
+ // 'text.stream': 'true',
24
+ // 'tts.disable': 'true',
25
+ // });
27
26
  }
28
27
  }, /*#__PURE__*/React.createElement(Image, {
29
28
  src: rollback,
@@ -1,7 +1,10 @@
1
1
  import React from 'react';
2
2
  import './index.less';
3
- import { WorkflowOption } from '@ray-js/t-agent-plugin-assistant';
4
3
  import { TileProps } from '../../types';
4
+ export interface WorkflowOption {
5
+ name: string;
6
+ value: string;
7
+ }
5
8
  type WorkflowTileEventPayload = {
6
9
  type: 'select';
7
10
  option: WorkflowOption;
package/dist/tiles/map.js CHANGED
@@ -12,6 +12,7 @@ import DocumentsTile from './DocumentsTile';
12
12
  import OperateCardTile from './OperateCardTile';
13
13
  import ExecuteCardTile from './ExecuteCardTile';
14
14
  import DividerTile from './DividerTile';
15
+ import FileTile from './FileTile';
15
16
  export const tileMap = {
16
17
  bubble: BubbleTile,
17
18
  image: ImageTile,
@@ -26,5 +27,6 @@ export const tileMap = {
26
27
  documents: DocumentsTile,
27
28
  operateCard: OperateCardTile,
28
29
  executeCard: ExecuteCardTile,
29
- divider: DividerTile
30
+ divider: DividerTile,
31
+ file: FileTile
30
32
  };
package/dist/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { ChatCardObject, ChatMessageObject, ChatTileObject } from '@ray-js/t-agent';
2
2
  import React from 'react';
3
3
  import { UIChatAgent } from './contexts';
4
+ import { LongPressResult } from './hooks';
4
5
  export interface TileProps<T = any, P = any> {
5
6
  side: 'start' | 'end' | string;
6
7
  message: ChatMessageObject;
@@ -32,6 +33,7 @@ export interface RenderOptions {
32
33
  renderTileAs: (props: TileProps) => React.ReactNode;
33
34
  renderCustomBlockAs: (block: MarkdownBlock) => React.ReactNode;
34
35
  renderCardAs: (card: ChatCardObject) => React.ReactNode;
36
+ renderLongPressAs: (res: LongPressResult) => React.ReactNode;
35
37
  customBlockTypes: string[];
36
38
  customCardMap: Record<string, ChatCardComponent>;
37
39
  getStaticResourceBizType: (src: string, scene?: string, data?: any) => string;
@@ -0,0 +1,24 @@
1
+ export declare function uploadMedia(type: 'video' | 'image', filePath: string, bizType: string): Promise<{
2
+ cloudKey: string;
3
+ publicUrl: string;
4
+ }>;
5
+ export declare function uploadVideo(filePath: string, bizType: string): Promise<{
6
+ cloudKey: string;
7
+ publicUrl: string;
8
+ }>;
9
+ export declare function uploadImage(filePath: string, bizType: string): Promise<{
10
+ cloudKey: string;
11
+ publicUrl: string;
12
+ }>;
13
+ export declare const isFullLink: (link?: string) => boolean;
14
+ export declare function parseCloudKey(link: string): string;
15
+ export declare function isLinkExpired(link: string): boolean;
16
+ export declare function getUrlByCloudKey(key: string): string | undefined;
17
+ export declare function setUrlByCloudKey(key: string, url: string): void;
18
+ export declare function resetUrlByCloudKey(key: string): void;
19
+ export declare const downloadSign: (cloudKey: string, bizType: string) => Promise<string> | undefined;
20
+ export declare function chooseImage(count?: number): Promise<string[]>;
21
+ export declare function chooseVideo(count?: number): Promise<{
22
+ thumbTempFilePath: string;
23
+ tempFilePath: string;
24
+ }[]>;
@@ -0,0 +1,190 @@
1
+ import "core-js/modules/es.regexp.exec.js";
2
+ import "core-js/modules/es.string.replace.js";
3
+ import "core-js/modules/web.dom-collections.iterator.js";
4
+ import { generateId } from '@ray-js/t-agent';
5
+ import Url from 'url-parse';
6
+ import logger from '../logger';
7
+ export async function uploadMedia(type, filePath, bizType) {
8
+ const filename = parseFileName(filePath);
9
+ const name = "".concat(generateId(), "-").concat(filename);
10
+ logger.log('uploadMedia', {
11
+ name
12
+ });
13
+ let ext = "".concat(name.split('.').pop());
14
+ if (ext === 'jpg') {
15
+ ext = 'jpeg';
16
+ }
17
+ const miniType = "".concat(type, "/").concat(ext);
18
+ const result = await new Promise((resolve, reject) => {
19
+ ty.uploadImage({
20
+ bizType,
21
+ filePath,
22
+ contentType: miniType,
23
+ success(res) {
24
+ const data = JSON.parse(res.result);
25
+ cloudKeyCache.set(data.bizUrl, data.publicUrl);
26
+ resolve({
27
+ cloudKey: data.bizUrl,
28
+ publicUrl: data.publicUrl
29
+ });
30
+ },
31
+ fail(err) {
32
+ logger.error('uploadMedia fail', err);
33
+ reject(err);
34
+ }
35
+ });
36
+ });
37
+ return result;
38
+ }
39
+ export async function uploadVideo(filePath, bizType) {
40
+ return uploadMedia('video', filePath, bizType);
41
+ }
42
+ export async function uploadImage(filePath, bizType) {
43
+ return uploadMedia('image', filePath, bizType);
44
+ }
45
+ export const isFullLink = function () {
46
+ let link = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
47
+ return /^https?:\/\//.test(link);
48
+ };
49
+ function parseFileName(fileUrl) {
50
+ try {
51
+ // 确保协议是 file
52
+ if (!fileUrl.startsWith('thingfile://')) {
53
+ throw new Error('URL protocol must be file');
54
+ }
55
+
56
+ // 移除协议部分
57
+ const filePath = decodeURIComponent(fileUrl.slice('thingfile://'.length));
58
+
59
+ // 提取文件名
60
+ return filePath.substring(filePath.lastIndexOf('/') + 1);
61
+ } catch (e) {
62
+ console.error(e);
63
+ return null;
64
+ }
65
+ }
66
+ export function parseCloudKey(link) {
67
+ if (!isFullLink(link)) {
68
+ return link.replace(/^\//, '');
69
+ }
70
+ const u = new Url(link);
71
+ return u.pathname.replace(/^\//, '');
72
+ }
73
+ function parseExpires(link) {
74
+ let expiresTime = Number.POSITIVE_INFINITY;
75
+ const u = new Url(link, true);
76
+ // 腾讯云
77
+ if (u.query['q-sign-time']) {
78
+ const cosTime = u.query['q-sign-time'];
79
+ expiresTime = +cosTime.split(';')[1] * 1000;
80
+ }
81
+
82
+ // AWS
83
+ if (u.query['X-Amz-Expires']) {
84
+ const xAmzDate = u.query['X-Amz-Date'];
85
+ const xAmzExpires = u.query['X-Amz-Expires'];
86
+ const year = parseInt(xAmzDate.substring(0, 4), 10);
87
+ const month = parseInt(xAmzDate.substring(4, 6), 10) - 1; // 月份从 0 开始
88
+ const day = parseInt(xAmzDate.substring(6, 8), 10);
89
+ const hour = parseInt(xAmzDate.substring(9, 11), 10);
90
+ const minute = parseInt(xAmzDate.substring(11, 13), 10);
91
+ const second = parseInt(xAmzDate.substring(13, 15), 10);
92
+ const requestDate = new Date(Date.UTC(year, month, day, hour, minute, second));
93
+ const expiresInSeconds = parseInt(xAmzExpires, 10);
94
+ expiresTime = requestDate.getTime() + expiresInSeconds * 1000;
95
+ }
96
+ return expiresTime;
97
+ }
98
+ export function isLinkExpired(link) {
99
+ // 非正常 URL 都认为是过期的
100
+ if (!link || !isFullLink(link)) {
101
+ return true;
102
+ }
103
+ const expiresTime = parseExpires(link);
104
+ return expiresTime < Date.now();
105
+ }
106
+ const cloudKeyCache = new Map();
107
+ export function getUrlByCloudKey(key) {
108
+ return cloudKeyCache.get(key);
109
+ }
110
+ export function setUrlByCloudKey(key, url) {
111
+ cloudKeyCache.set(key, url);
112
+ }
113
+ export function resetUrlByCloudKey(key) {
114
+ cloudKeyCache.delete(key);
115
+ }
116
+ const downloadSignPromises = new Map();
117
+ export const downloadSign = cloudKey => {
118
+ if (isFullLink(cloudKey)) {
119
+ cloudKey = parseCloudKey(cloudKey);
120
+ }
121
+ const url = getUrlByCloudKey(cloudKey);
122
+ if (url && !isLinkExpired(url)) {
123
+ return Promise.resolve(url);
124
+ }
125
+ if (downloadSignPromises.has(cloudKey)) {
126
+ return downloadSignPromises.get(cloudKey);
127
+ }
128
+ throw new Error('Not Implemented');
129
+
130
+ // const promise = apiRequestByAtop({
131
+ // api: 'tuya.web.fastroute.download.sign',
132
+ // version: '2.0',
133
+ // postData: {
134
+ // biz: bizType,
135
+ // signedRequest: {
136
+ // bucketName: '',
137
+ // resources: [
138
+ // {
139
+ // objectKey: cloudKey,
140
+ // responseHeaderOverrides: {},
141
+ // },
142
+ // ],
143
+ // },
144
+ // },
145
+ // })
146
+ // .then(({ data }) => {
147
+ // const ret = safeParseJSON(data);
148
+ // cloudKeyCache.set(cloudKey, ret.signedUrls[cloudKey]);
149
+ // return ret.signedUrls[cloudKey] as string;
150
+ // })
151
+ // .finally(() => {
152
+ // downloadSignPromises.delete(cloudKey);
153
+ // });
154
+ //
155
+ // downloadSignPromises.set(cloudKey, promise);
156
+ //
157
+ // return promise;
158
+ };
159
+ export async function chooseImage() {
160
+ let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
161
+ const paths = await new Promise((resolve, reject) => {
162
+ ty.chooseImage({
163
+ count,
164
+ sizeType: ['compressed'],
165
+ success(res) {
166
+ resolve(res.tempFilePaths);
167
+ },
168
+ fail(err) {
169
+ reject(err);
170
+ }
171
+ });
172
+ });
173
+ return paths;
174
+ }
175
+ export async function chooseVideo() {
176
+ let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
177
+ const paths = await new Promise((resolve, reject) => {
178
+ ty.chooseMedia({
179
+ count,
180
+ mediaType: 'video',
181
+ success(res) {
182
+ resolve(res.tempFiles);
183
+ },
184
+ fail(err) {
185
+ reject(err);
186
+ }
187
+ });
188
+ });
189
+ return paths;
190
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/t-agent-ui-ray",
3
- "version": "0.1.1",
3
+ "version": "0.2.0-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": "e97f7ef72e4d5d366b5bf923525ca2e064248ab5"
44
+ "gitHead": "98229f8a9cb090a6fa0d9b47fa70b1f44ec2b34a"
45
45
  }