@ray-js/t-agent-ui-ray 0.2.8-beta.1 → 0.2.8-beta.3

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 (45) hide show
  1. package/README-zh_CN.md +337 -87
  2. package/README.md +916 -706
  3. package/dist/LowCodeCardRender/index.js +1 -0
  4. package/dist/MessageInput/MessageInputAIStream/index.js +2 -24
  5. package/dist/MessageInput/index.js +1 -0
  6. package/dist/MessageList/ScrollBottomView.d.ts +2 -2
  7. package/dist/PrivateImage/index.js +7 -10
  8. package/dist/contexts.d.ts +0 -1
  9. package/dist/hooks/context.d.ts +1 -1
  10. package/dist/hooks/useAttachmentInput.d.ts +1 -2
  11. package/dist/i18n/strings.js +1 -0
  12. package/dist/index.js +1 -0
  13. package/dist/renderOption.js +7 -6
  14. package/dist/tiles/BubbleTile/index.d.ts +15 -1
  15. package/dist/tiles/BubbleTile/index.js +60 -68
  16. package/dist/tiles/BubbleToolTile/audio-play.svg +1 -0
  17. package/dist/tiles/BubbleToolTile/audio-playing.svg +24 -0
  18. package/dist/tiles/BubbleToolTile/copy.svg +1 -0
  19. package/dist/tiles/BubbleToolTile/index.d.ts +10 -0
  20. package/dist/tiles/BubbleToolTile/index.js +63 -0
  21. package/dist/tiles/BubbleToolTile/index.less +46 -0
  22. package/dist/tiles/CardTile/index.d.ts +1 -1
  23. package/dist/tiles/DividerTile/index.d.ts +1 -1
  24. package/dist/tiles/OperateCardTile/Expand.d.ts +1 -1
  25. package/dist/tiles/TextTile/index.d.ts +1 -1
  26. package/dist/tiles/TimeTile/index.js +17 -16
  27. package/dist/tiles/TipTile/index.d.ts +1 -1
  28. package/dist/tiles/map.js +3 -3
  29. package/dist/tiles/types.d.ts +1 -1
  30. package/dist/utils/abort.js +1 -0
  31. package/dist/utils/createSharedStore.d.ts +2 -2
  32. package/dist/utils/getMessageContent.d.ts +11 -0
  33. package/dist/utils/getMessageContent.js +49 -0
  34. package/dist/utils/index.d.ts +1 -0
  35. package/dist/utils/index.js +3 -1
  36. package/dist/utils/ttt.d.ts +1 -0
  37. package/dist/utils/ttt.js +24 -0
  38. package/package.json +5 -4
  39. package/dist/tiles/WorkflowTile/RollBack/index.d.ts +0 -5
  40. package/dist/tiles/WorkflowTile/RollBack/index.js +0 -27
  41. package/dist/tiles/WorkflowTile/RollBack/index.less +0 -20
  42. package/dist/tiles/WorkflowTile/RollBack/workflow-rollback.png +0 -0
  43. package/dist/tiles/WorkflowTile/index.d.ts +0 -21
  44. package/dist/tiles/WorkflowTile/index.js +0 -32
  45. package/dist/tiles/WorkflowTile/index.less +0 -31
package/dist/tiles/map.js CHANGED
@@ -7,12 +7,12 @@ import VideoTile from './VideoTile';
7
7
  import ButtonGroupTile from './ButtonsTile';
8
8
  import RecommendationsTile from './RecommendationsTile';
9
9
  import CardTile from './CardTile';
10
- import WorkflowTile from './WorkflowTile';
11
10
  import DocumentsTile from './DocumentsTile';
12
11
  import OperateCardTile from './OperateCardTile';
13
12
  import ExecuteCardTile from './ExecuteCardTile';
14
13
  import DividerTile from './DividerTile';
15
14
  import FileTile from './FileTile';
15
+ import BubbleToolTile from './BubbleToolTile';
16
16
  export const tileMap = {
17
17
  bubble: BubbleTile,
18
18
  image: ImageTile,
@@ -23,10 +23,10 @@ export const tileMap = {
23
23
  buttons: ButtonGroupTile,
24
24
  recommendations: RecommendationsTile,
25
25
  card: CardTile,
26
- workflow: WorkflowTile,
27
26
  documents: DocumentsTile,
28
27
  operateCard: OperateCardTile,
29
28
  executeCard: ExecuteCardTile,
30
29
  divider: DividerTile,
31
- file: FileTile
30
+ file: FileTile,
31
+ bubbleTool: BubbleToolTile
32
32
  };
@@ -1,5 +1,5 @@
1
1
  export declare enum SceneType {
2
- EXECUTE = 1,
2
+ EXECUTE = 1,// 一键执行
3
3
  AUTO = 2
4
4
  }
5
5
  export interface SceneInfoItem {
@@ -1,5 +1,6 @@
1
1
  import "core-js/modules/es.symbol.description.js";
2
2
  import "core-js/modules/web.dom-collections.iterator.js";
3
+ /* istanbul ignore file */
3
4
  // source: https://github.com/mo/abortcontroller-polyfill
4
5
  import { Emitter } from '@ray-js/t-agent';
5
6
  function createAbortEvent(reason) {
@@ -1,4 +1,4 @@
1
1
  import React, { PropsWithChildren } from 'react';
2
- export declare function createSharedStore<T>(): readonly [({ value, children }: React.PropsWithChildren<{
2
+ export declare function createSharedStore<T>(): readonly [({ value, children }: PropsWithChildren<{
3
3
  value: T;
4
- }>) => React.JSX.Element, <K extends keyof T>(key: K) => T[K], <K_1 extends keyof T>(key: K_1) => [T[K_1], (v: T[K_1]) => void]];
4
+ }>) => React.JSX.Element, <K extends keyof T>(key: K) => T[K], <K extends keyof T>(key: K) => [T[K], (v: T[K]) => void]];
@@ -0,0 +1,11 @@
1
+ import { ChatMessageObject } from '@ray-js/t-agent';
2
+ /**
3
+ * 从 message 中提取文本内容。
4
+ *
5
+ * 遍历 message 的所有 tile,取第一个能解析出文本的 tile:
6
+ * - 若 tile 自身为 `text` 类型,返回其文本;
7
+ * - 否则查找其 children 中的第一个 `text` 类型 tile 并返回文本。
8
+ *
9
+ * 可在任意 tile 中复用,例如长按复制消息内容。
10
+ */
11
+ export declare function getMessageContent(message?: ChatMessageObject): string;
@@ -0,0 +1,49 @@
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.find.js";
3
+ const getTileText = data => {
4
+ if (data && typeof data === 'object' && 'text' in data) {
5
+ return data.text || '';
6
+ }
7
+ return '';
8
+ };
9
+ const getTextFromTile = tile => {
10
+ if (!tile) {
11
+ return '';
12
+ }
13
+
14
+ // 如果是文本类型的 tile,直接获取文本内容
15
+ if (tile.type === 'text') {
16
+ return getTileText(tile.data);
17
+ }
18
+
19
+ // 查找子 tile 中的文本类型 tile
20
+ if (tile.children && tile.children.length > 0) {
21
+ const textTile = tile.children.find(child => child.type === 'text');
22
+ if (textTile) {
23
+ return getTileText(textTile.data);
24
+ }
25
+ }
26
+ return '';
27
+ };
28
+
29
+ /**
30
+ * 从 message 中提取文本内容。
31
+ *
32
+ * 遍历 message 的所有 tile,取第一个能解析出文本的 tile:
33
+ * - 若 tile 自身为 `text` 类型,返回其文本;
34
+ * - 否则查找其 children 中的第一个 `text` 类型 tile 并返回文本。
35
+ *
36
+ * 可在任意 tile 中复用,例如长按复制消息内容。
37
+ */
38
+ export function getMessageContent(message) {
39
+ if (!message || !message.tiles || message.tiles.length === 0) {
40
+ return '';
41
+ }
42
+ for (let i = 0; i < message.tiles.length; i++) {
43
+ const content = getTextFromTile(message.tiles[i]);
44
+ if (content) {
45
+ return content;
46
+ }
47
+ }
48
+ return '';
49
+ }
@@ -1,3 +1,4 @@
1
1
  export declare function routeScene(sceneId: string): void;
2
2
  export declare const systemInfo: any;
3
3
  export * from './formatMessage';
4
+ export * from './getMessageContent';
@@ -1,3 +1,4 @@
1
+ /* istanbul ignore file */
1
2
  export function routeScene(sceneId) {
2
3
  ty.router({
3
4
  url: "thingSmart://editScene?sceneId=".concat(sceneId, "&biz_type=ai_smart&action=edit"),
@@ -11,4 +12,5 @@ export function routeScene(sceneId) {
11
12
  });
12
13
  }
13
14
  export const systemInfo = ty.getSystemInfoSync();
14
- export * from './formatMessage';
15
+ export * from './formatMessage';
16
+ export * from './getMessageContent';
@@ -96,3 +96,4 @@ export declare const getCurrentHomeInfo: () => Promise<{
96
96
  homeId: string;
97
97
  homeName: string;
98
98
  }>;
99
+ export declare const initAudioRecorder: () => Promise<void>;
package/dist/utils/ttt.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ /* istanbul ignore file */
3
+ import logger from '../logger';
2
4
  export const authorize = _ref => {
3
5
  let {
4
6
  scope
@@ -51,4 +53,26 @@ export const getCurrentHomeInfo = () => {
51
53
  }
52
54
  });
53
55
  });
56
+ };
57
+ export const initAudioRecorder = () => {
58
+ return new Promise(resolve => {
59
+ if (!ty.aistream.initAudioRecorder) {
60
+ resolve();
61
+ return;
62
+ }
63
+ try {
64
+ ty.aistream.initAudioRecorder({
65
+ success: () => {
66
+ resolve();
67
+ },
68
+ fail: error => {
69
+ logger.error('MessageInputAIStream', 'initAudioRecorder error', error);
70
+ resolve();
71
+ }
72
+ });
73
+ } catch (error) {
74
+ logger.error('MessageInputAIStream', 'initAudioRecorder error', error);
75
+ resolve();
76
+ }
77
+ });
54
78
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/t-agent-ui-ray",
3
- "version": "0.2.8-beta.1",
3
+ "version": "0.2.8-beta.3",
4
4
  "author": "Tuya.inc",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -21,11 +21,12 @@
21
21
  "scripts": {
22
22
  "dev": "ray start --type=component --output dist --emit-declaration-dev",
23
23
  "build": "ray build --type=component --output dist",
24
- "clean": "rimraf ./dist"
24
+ "clean": "rimraf ./dist",
25
+ "test": "jest --runInBand",
26
+ "test:coverage": "jest --runInBand --coverage"
25
27
  },
26
28
  "dependencies": {
27
29
  "clsx": "^1.2.1",
28
- "dayjs": "^1.10.4",
29
30
  "echarts": "^5.5.0",
30
31
  "markdown-it": "^14.1.0",
31
32
  "markdown-it-emoji": "^3.0.0",
@@ -40,5 +41,5 @@
40
41
  "@types/echarts": "^4.9.22",
41
42
  "@types/markdown-it": "^14.1.1"
42
43
  },
43
- "gitHead": "040499ca11aedda3246121f880807da0f8af3cc9"
44
+ "gitHead": "938bc0c7da7d23dbbad8c3c14c97e5f4007f06f7"
44
45
  }
@@ -1,5 +0,0 @@
1
- import './index.less';
2
- import React from 'react';
3
- export default function RollBack(props: {
4
- nodeId: string;
5
- }): React.JSX.Element;
@@ -1,27 +0,0 @@
1
- import './index.less';
2
- import { Image, View } from '@ray-js/ray';
3
- import React from 'react';
4
- import rollback from './workflow-rollback.png';
5
- import { useTileProps } from '../../../hooks';
6
- export default function RollBack(props) {
7
- const {
8
- nodeId
9
- } = props;
10
- const {
11
- emitTileEvent
12
- } = useTileProps();
13
- return /*#__PURE__*/React.createElement(View, {
14
- className: "t-agent-workflow-rollback-tile",
15
- onClick: async () => {
16
- emitTileEvent({
17
- type: 'rollback',
18
- nodeId
19
- });
20
- }
21
- }, /*#__PURE__*/React.createElement(Image, {
22
- src: rollback,
23
- className: "t-agent-workflow-rollback-tile-image"
24
- }), /*#__PURE__*/React.createElement(View, {
25
- className: "t-agent-workflow-rollback-tile-text"
26
- }, "\u91CD\u9009"));
27
- }
@@ -1,20 +0,0 @@
1
- .t-agent-workflow-rollback-tile {
2
- color: var(--app-B3-N1);
3
- background-color: var(--app-B3);
4
- border-radius: 9999px;
5
- height: 36px;
6
- margin-top: 8px;
7
- width: fit-content;
8
- line-height: 36px;
9
- padding: 0 12px;
10
- display: flex;
11
- align-items: center;
12
- justify-content: center;
13
- .t-agent-workflow-rollback-tile-image {
14
- width: 20px;
15
- height: 20px;
16
- margin-right: 6px;
17
- }
18
- .t-agent-workflow-rollback-tile-text {
19
- }
20
- }
@@ -1,21 +0,0 @@
1
- import React from 'react';
2
- import './index.less';
3
- import { TileProps } from '../../types';
4
- export interface WorkflowOption {
5
- name: string;
6
- value: string;
7
- }
8
- type WorkflowTileEventPayload = {
9
- type: 'select';
10
- option: WorkflowOption;
11
- selected: number;
12
- } | {
13
- type: 'rollback';
14
- nodeId: string;
15
- };
16
- export default function WorkflowTile(props: TileProps<{
17
- selected: number | null;
18
- options: WorkflowOption[];
19
- nodeId: string | null;
20
- }, WorkflowTileEventPayload>): React.JSX.Element;
21
- export {};
@@ -1,32 +0,0 @@
1
- import "core-js/modules/esnext.iterator.constructor.js";
2
- import "core-js/modules/esnext.iterator.map.js";
3
- import { Button, View } from '@ray-js/components';
4
- import React from 'react';
5
- import './index.less';
6
- import cx from 'clsx';
7
- export default function WorkflowTile(props) {
8
- const {
9
- options,
10
- selected
11
- } = props.tile.data;
12
- const isLatest = props.isLatestMessage;
13
- return /*#__PURE__*/React.createElement(View, {
14
- className: "t-agent-workflow-tile"
15
- }, options.map((item, index) => /*#__PURE__*/React.createElement(Button, {
16
- key: "".concat(item.name),
17
- className: cx({
18
- 't-agent-workflow-tile-option': true,
19
- 't-agent-workflow-tile-option-locked': selected != null && selected !== index || !isLatest,
20
- 't-agent-workflow-tile-option-selected': selected === index
21
- }),
22
- onClick: () => {
23
- if (isLatest && selected == null) {
24
- props.emitTileEvent({
25
- type: 'select',
26
- option: item,
27
- selected: index
28
- });
29
- }
30
- }
31
- }, item.name)));
32
- }
@@ -1,31 +0,0 @@
1
- .t-agent-workflow-tile {
2
- margin-top: var(--t-agent-y-gap);
3
- }
4
-
5
- .t-agent-workflow-tile > :not([hidden])~:not([hidden]) {
6
- margin-top: 16rpx;
7
- margin-bottom: 0;
8
- }
9
-
10
- .t-agent-workflow-tile-option {
11
- display: flex;
12
- align-items: center;
13
- padding: 36rpx;
14
- min-width: 564rpx;
15
- height: 96rpx;
16
- margin-top: 24rpx;
17
- font-size: 32rpx;
18
- background: var(--app-B1);
19
- border-radius: var(--app-C1_1);
20
- font-weight: normal;
21
- color: var(--app-B3-N1);
22
- }
23
-
24
- .t-agent-workflow-tile-option-locked {
25
- opacity: 0.5;
26
- }
27
-
28
- .t-agent-workflow-tile-option-selected {
29
- background: var(--app-B3-N9);
30
- color: var(--app-M1);
31
- }