@ray-js/t-agent-ui-ray 0.1.0-beta-3 → 0.1.0-beta-4

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.
@@ -49,8 +49,7 @@ export default function ChatContainer(props) {
49
49
  plugins: agent.plugins,
50
50
  pushInputBlocks: agent.pushInputBlocks,
51
51
  emitTileEvent: agent.emitTileEvent,
52
- removeMessage: agent.removeMessage,
53
- removeMessageByChannel: agent.removeMessageByChannel
52
+ removeMessage: agent.removeMessage
54
53
  };
55
54
  }, [agent]);
56
55
  useEffect(() => {
@@ -9,7 +9,7 @@ export declare const MessageContext: import("react").Context<{
9
9
  }>;
10
10
  export declare const RenderContext: import("react").Context<RenderOptions>;
11
11
  export type UIChatSession = Pick<ChatSession, 'get' | 'getData' | 'set' | 'sessionId'>;
12
- export type UIChatAgent = Pick<ChatAgent<UIPlugin & AssistantPlugin>, 'pushInputBlocks' | 'plugins' | 'emitTileEvent' | 'removeMessage' | 'removeMessageByChannel'> & {
12
+ export type UIChatAgent = Pick<ChatAgent<UIPlugin & AssistantPlugin>, 'pushInputBlocks' | 'plugins' | 'emitTileEvent' | 'removeMessage'> & {
13
13
  session: UIChatSession;
14
14
  };
15
15
  export declare const ChatAgentContext: import("react").Context<UIChatAgent>;
@@ -4,7 +4,6 @@ import "core-js/modules/esnext.iterator.for-each.js";
4
4
  import "core-js/modules/esnext.iterator.map.js";
5
5
  import "core-js/modules/web.dom-collections.iterator.js";
6
6
  import { useState, useEffect, useCallback } from 'react';
7
- import { setClipboardData, showModal, showToast, vibrateShort } from '@ray-js/ray';
8
7
  import logger from '../logger';
9
8
  import { useRenderOptions } from './context';
10
9
  import { useChatAgent } from '.';
@@ -67,10 +66,10 @@ export function useLongPress() {
67
66
  action: () => {
68
67
  const content = getMessageContent();
69
68
  if (content) {
70
- setClipboardData({
69
+ ty.setClipboardData({
71
70
  data: content,
72
71
  success: () => {
73
- showToast({
72
+ ty.showToast({
74
73
  title: t('t-agent.message.copy.success'),
75
74
  icon: 'none'
76
75
  });
@@ -88,13 +87,13 @@ export function useLongPress() {
88
87
  label: t('t-agent.message.action.delete'),
89
88
  action: () => {
90
89
  if (typeof agent.removeMessage === 'function') {
91
- showModal({
90
+ ty.showModal({
92
91
  title: t('t-agent.message.delete.title'),
93
92
  content: t('t-agent.message.delete.content'),
94
93
  success: res => {
95
94
  if (res.confirm) {
96
95
  agent.removeMessage(message.id);
97
- showToast({
96
+ ty.showToast({
98
97
  title: t('t-agent.message.delete.success'),
99
98
  icon: 'none'
100
99
  });
@@ -112,8 +111,11 @@ export function useLongPress() {
112
111
  label: t('t-agent.message.action.deleteByChannel'),
113
112
  action: () => {
114
113
  const channel = agent.session.get('AIAssistant.channel');
115
- if (typeof agent.removeMessageByChannel === 'function') {
116
- agent.removeMessageByChannel(channel);
114
+ const {
115
+ removeMessageByChannel
116
+ } = agent.plugins.assistant;
117
+ if (typeof removeMessageByChannel === 'function') {
118
+ removeMessageByChannel(channel);
117
119
  }
118
120
  }
119
121
  });
@@ -123,7 +125,7 @@ export function useLongPress() {
123
125
  key: 'like',
124
126
  label: t('t-agent.message.action.like'),
125
127
  action: () => {
126
- showToast({
128
+ ty.showToast({
127
129
  title: t('t-agent.message.like.success'),
128
130
  icon: 'none'
129
131
  });
@@ -135,7 +137,7 @@ export function useLongPress() {
135
137
  key: 'unlike',
136
138
  label: t('t-agent.message.action.unlike'),
137
139
  action: () => {
138
- showToast({
140
+ ty.showToast({
139
141
  title: t('t-agent.message.unlike.success'),
140
142
  icon: 'none'
141
143
  });
@@ -195,7 +197,7 @@ export function useLongPress() {
195
197
  isClosing: false,
196
198
  menuPosition: adjustedPosition
197
199
  });
198
- vibrateShort({
200
+ ty.vibrateShort({
199
201
  type: 'light'
200
202
  });
201
203
  if (e.origin && e.origin.stopPropagation) {
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { ChangeInfoItem, DeviceInfoItem, SceneInfoItem } from '@ray-js/t-agent-plugin-assistant';
3
+ import './index.less';
4
+ import { TileProps } from '../../types';
5
+ export interface ExecuteCardTileData {
6
+ deviceInfo: DeviceInfoItem[];
7
+ sceneInfo: SceneInfoItem[];
8
+ deviceShareInfo: ChangeInfoItem[];
9
+ }
10
+ export default function ExecuteCardTile(props: TileProps<ExecuteCardTileData>): React.JSX.Element | null;
@@ -0,0 +1,233 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import "core-js/modules/esnext.iterator.constructor.js";
3
+ import "core-js/modules/esnext.iterator.for-each.js";
4
+ import "core-js/modules/esnext.iterator.map.js";
5
+ import { Image, Switch, Text, View } from '@ray-js/components';
6
+ import React, { useMemo } from 'react';
7
+ import { SceneType } from '@ray-js/t-agent-plugin-assistant';
8
+ import './index.less';
9
+ import { triggerRule } from '@ray-js/ray';
10
+ import { routeScene } from '../../utils';
11
+ import lockPng from '../OperateCardTile/lock.png';
12
+ import bookmark from './bookmark.png';
13
+ import { useRenderOptions } from '../../hooks';
14
+ export default function ExecuteCardTile(props) {
15
+ const {
16
+ tile
17
+ } = props;
18
+ const {
19
+ deviceInfo,
20
+ sceneInfo,
21
+ deviceShareInfo
22
+ } = tile.data || {};
23
+ const {
24
+ i18nTranslate: t
25
+ } = useRenderOptions();
26
+ const {
27
+ cards
28
+ } = useMemo(() => {
29
+ const cards = [];
30
+ if (deviceInfo !== null && deviceInfo !== void 0 && deviceInfo.length) {
31
+ deviceInfo.forEach(i => {
32
+ const {
33
+ intent
34
+ } = i;
35
+ switch (intent) {
36
+ case 'controlDevice':
37
+ break;
38
+ default:
39
+ cards.push(_objectSpread(_objectSpread({}, i), {}, {
40
+ displayType: 'device'
41
+ }));
42
+ break;
43
+ }
44
+ });
45
+ }
46
+ if (sceneInfo !== null && sceneInfo !== void 0 && sceneInfo.length) {
47
+ sceneInfo.forEach(i => {
48
+ if (i.valid == null) {
49
+ i.valid = true;
50
+ }
51
+ const {
52
+ intent,
53
+ type
54
+ } = i;
55
+ const displayType = type === SceneType.EXECUTE ? 'execute' : 'scene';
56
+ switch (intent) {
57
+ case 'queryScene':
58
+ case 'updateScene':
59
+ cards.push(_objectSpread(_objectSpread({}, i), {}, {
60
+ displayType
61
+ }));
62
+ break;
63
+ case 'deleteScene':
64
+ if (!i.success) {
65
+ cards.push(_objectSpread(_objectSpread({}, i), {}, {
66
+ displayType
67
+ }));
68
+ }
69
+ break;
70
+ default:
71
+ break;
72
+ }
73
+ });
74
+ }
75
+ if (deviceShareInfo !== null && deviceShareInfo !== void 0 && deviceShareInfo.length) {
76
+ deviceShareInfo.forEach(i => {
77
+ cards.push(_objectSpread(_objectSpread({}, i), {}, {
78
+ displayType: 'device'
79
+ }));
80
+ });
81
+ }
82
+ return {
83
+ cards
84
+ };
85
+ }, [deviceInfo, sceneInfo]);
86
+ if (!cards.length) {
87
+ return null;
88
+ }
89
+ const handleTap = card => {
90
+ const {
91
+ deviceId,
92
+ intent
93
+ } = card;
94
+ if (intent === 'shareDevice') {
95
+ ty.router({
96
+ url: "tuyaSmart://thing_single_device_share?devId=".concat(deviceId),
97
+ fail(err) {
98
+ console.error('router thing_single_device_share fail', err);
99
+ }
100
+ });
101
+ return;
102
+ }
103
+ ty.openPanel({
104
+ deviceId,
105
+ fail() {
106
+ ty.showToast({
107
+ title: t('t-agent.execute-card-tile.execution.failed'),
108
+ icon: 'error'
109
+ });
110
+ }
111
+ });
112
+ };
113
+ const changeScene = (e, card) => {
114
+ const {
115
+ sceneId
116
+ } = card;
117
+ };
118
+ const deleteScene = (e, card) => {
119
+ var _e$origin;
120
+ e === null || e === void 0 || (_e$origin = e.origin) === null || _e$origin === void 0 || _e$origin.stopPropagation();
121
+ const {
122
+ sceneId
123
+ } = card;
124
+ ty.router({
125
+ url: "tuyaSmart://editScene?sceneId=".concat(sceneId, "&biz_type=ai_smart&action=delete"),
126
+ fail: console.error
127
+ });
128
+ };
129
+ const enterScene = card => {
130
+ const {
131
+ sceneId,
132
+ valid
133
+ } = card;
134
+ if (!valid) {
135
+ ty.showToast({
136
+ title: t('t-agent.execute-card-tile.scene.invalid'),
137
+ image: '/assets/images/notice.png'
138
+ });
139
+ return;
140
+ }
141
+ routeScene(sceneId);
142
+ };
143
+ const execute = (e, card) => {
144
+ var _e$origin2;
145
+ e === null || e === void 0 || (_e$origin2 = e.origin) === null || _e$origin2 === void 0 || _e$origin2.stopPropagation();
146
+ const {
147
+ sceneId
148
+ } = card;
149
+ triggerRule({
150
+ ruleId: sceneId
151
+ }).then(() => {
152
+ ty.showToast({
153
+ title: t('t-agent.execute-card-tile.execution.success'),
154
+ icon: 'success'
155
+ });
156
+ }).catch(() => {
157
+ ty.showToast({
158
+ title: t('t-agent.execute-card-tile.execution.failed'),
159
+ icon: 'error'
160
+ });
161
+ });
162
+ };
163
+ return /*#__PURE__*/React.createElement(View, {
164
+ className: "t-agent-execute-card-tile"
165
+ }, cards.map(card => {
166
+ return /*#__PURE__*/React.createElement(View, {
167
+ className: "t-agent-execute-card-tile-card"
168
+ }, card.displayType === 'device' && /*#__PURE__*/React.createElement(View, {
169
+ className: "t-agent-execute-card-tile-device",
170
+ onClick: () => handleTap(card)
171
+ }, /*#__PURE__*/React.createElement(Image, {
172
+ src: card.icon,
173
+ mode: "widthFix",
174
+ className: "t-agent-execute-card-tile-device-icon"
175
+ }), /*#__PURE__*/React.createElement(View, null, card.name)), card.displayType === 'energy' && /*#__PURE__*/React.createElement(View, {
176
+ className: "t-agent-execute-card-tile-energy",
177
+ onClick: () => handleTap(card)
178
+ }, /*#__PURE__*/React.createElement(Image, {
179
+ src: card.icon,
180
+ mode: "widthFix",
181
+ className: "t-agent-execute-card-tile-energy-icon"
182
+ }), /*#__PURE__*/React.createElement(View, {
183
+ className: "t-agent-execute-card-tile-energy-content"
184
+ }, /*#__PURE__*/React.createElement(View, {
185
+ className: "t-agent-execute-card-tile-energy-content-title"
186
+ }, card.name), /*#__PURE__*/React.createElement(View, {
187
+ className: "t-agent-execute-card-tile-energy-content-desc"
188
+ }, card.desc))), card.displayType === 'scene' && /*#__PURE__*/React.createElement(View, {
189
+ className: "t-agent-execute-card-tile-scene",
190
+ onClick: () => enterScene(card)
191
+ }, /*#__PURE__*/React.createElement(View, {
192
+ className: "t-agent-execute-card-tile-scene-icon-wrapper",
193
+ style: {
194
+ backgroundColor: "#".concat(card.displayColor)
195
+ }
196
+ }, /*#__PURE__*/React.createElement(Image, {
197
+ src: card.icon || bookmark,
198
+ mode: "widthFix",
199
+ className: "t-agent-execute-card-tile-scene-icon"
200
+ })), /*#__PURE__*/React.createElement(View, {
201
+ className: "t-agent-execute-card-tile-scene-name"
202
+ }, card.name, card.room && /*#__PURE__*/React.createElement(Text, null, "-", card.room)), card.valid && card.intent !== 'deleteScene' ? /*#__PURE__*/React.createElement(View, {
203
+ onClick: e => {
204
+ var _e$origin3;
205
+ return e === null || e === void 0 || (_e$origin3 = e.origin) === null || _e$origin3 === void 0 ? void 0 : _e$origin3.stopPropagation();
206
+ }
207
+ }, /*#__PURE__*/React.createElement(Switch, {
208
+ checked: card.enabled,
209
+ onChange: e => changeScene(e, card)
210
+ })) : /*#__PURE__*/React.createElement(View, {
211
+ className: "t-agent-execute-card-tile-scene-delete",
212
+ onClick: e => deleteScene(e, card)
213
+ }, t('t-agent.execute-card-tile.delete'))), card.displayType === 'execute' && /*#__PURE__*/React.createElement(View, {
214
+ className: "t-agent-execute-card-tile-execute ".concat(!card.valid ? 't-agent-execute-card-tile-execute-disabled' : ''),
215
+ style: {
216
+ backgroundColor: "#".concat(card.displayColor)
217
+ },
218
+ onClick: () => enterScene(card)
219
+ }, /*#__PURE__*/React.createElement(Image, {
220
+ src: card.icon || lockPng,
221
+ mode: "widthFix",
222
+ className: "t-agent-execute-card-tile-execute-icon"
223
+ }), /*#__PURE__*/React.createElement(View, {
224
+ className: "t-agent-execute-card-tile-execute-name"
225
+ }, card.name, card.room && /*#__PURE__*/React.createElement(Text, null, "-", card.room)), /*#__PURE__*/React.createElement(View, {
226
+ className: "t-agent-execute-card-tile-execute-button",
227
+ onClick: e => execute(e, card),
228
+ style: {
229
+ color: "#".concat(card.displayColor)
230
+ }
231
+ }, t('t-agent.execute-card-tile.execute'))));
232
+ }));
233
+ }
@@ -0,0 +1,154 @@
1
+ .t-agent-execute-card-tile {
2
+ .t-agent-execute-card-tile-card {
3
+ .t-agent-execute-card-tile-device {
4
+ display: flex;
5
+ align-items: center;
6
+ min-height: 44px;
7
+ background-color: var(--app-B1);
8
+ padding: 12px;
9
+ border-radius: var(--app-C1_1);
10
+ margin-top: 8px;
11
+
12
+ .t-agent-execute-card-tile-device-icon {
13
+ width: 40px;
14
+ height: 40px;
15
+ margin-right: 10px;
16
+ }
17
+ }
18
+
19
+ .t-agent-execute-card-tile-energy {
20
+ display: flex;
21
+ align-items: center;
22
+ min-height: 44px;
23
+ background-color: var(--app-B1);
24
+ padding: 12px;
25
+ border-radius: var(--app-C1_1);
26
+ margin-top: 8px;
27
+
28
+ .t-agent-execute-card-tile-energy-icon {
29
+ width: 32px;
30
+ height: 32px;
31
+ border-radius: 4px;
32
+ }
33
+
34
+ .t-agent-execute-card-tile-energy-content {
35
+ margin-left: 8px;
36
+ flex: 1;
37
+ .t-agent-execute-card-tile-energy-content-title {
38
+ font-size: 16px;
39
+ color: var(--app-C1);
40
+ line-height: 22px;
41
+ overflow: hidden;
42
+ text-overflow: ellipsis;
43
+ display: -webkit-box;
44
+ -webkit-line-clamp: 2;
45
+ -webkit-box-orient: vertical;
46
+ }
47
+
48
+ .t-agent-execute-card-tile-energy-content-desc {
49
+ font-size: 13px;
50
+ color: var(--app-B1-N3);
51
+ line-height: 18px;
52
+ overflow: hidden;
53
+ text-overflow: ellipsis;
54
+ display: -webkit-box;
55
+ -webkit-line-clamp: 2;
56
+ -webkit-box-orient: vertical;
57
+ }
58
+ }
59
+ }
60
+
61
+ .t-agent-execute-card-tile-scene {
62
+ min-height: 44px;
63
+ background-color: var(--app-B1);
64
+ display: flex;
65
+ align-items: center;
66
+ padding: 12px;
67
+ border-radius: var(--app-C1_1);
68
+ margin-top: 8px;
69
+
70
+ .t-agent-execute-card-tile-scene-icon-wrapper {
71
+ display: flex;
72
+ justify-content: center;
73
+ align-items: center;
74
+ width: 32px;
75
+ height: 32px;
76
+ border-radius: 10px;
77
+ margin-right: 8px;
78
+ .t-agent-execute-card-tile-scene-icon {
79
+ width: 20px;
80
+ height: 20px;
81
+ filter: brightness(100);
82
+ }
83
+ }
84
+
85
+ .t-agent-execute-card-tile-scene-name {
86
+ flex: 1;
87
+ font-size: 16px;
88
+ line-height: 22px;
89
+ color: var(--app-C1);
90
+ }
91
+
92
+ .t-agent-execute-card-tile-scene-switch {
93
+ margin-left: auto;
94
+ }
95
+
96
+ .t-agent-execute-card-tile-scene-delete {
97
+ display: flex;
98
+ align-items: center;
99
+ height: 24px;
100
+ padding-right: 12px;
101
+ padding-left: 12px;
102
+ color: var(--app-M2);
103
+ background: #fff;
104
+ border-radius: var(--app-C1_1);
105
+ font-size: 12px;
106
+ }
107
+ }
108
+
109
+ .t-agent-execute-card-tile-execute {
110
+ display: flex;
111
+ align-items: center;
112
+ min-height: 44px;
113
+ background-color: #e36468;
114
+ padding: 12px;
115
+ border-radius: var(--app-C1_1);
116
+ margin-top: 8px;
117
+
118
+ &.t-agent-execute-card-tile-execute-disabled {
119
+ opacity: 0.3;
120
+ }
121
+
122
+ .t-agent-execute-card-tile-execute-icon {
123
+ width: 40px;
124
+ height: 40px;
125
+ margin-right: 10px;
126
+ }
127
+
128
+ .t-agent-execute-card-tile-execute-name {
129
+ font-size: 16px;
130
+ line-height: 22px;
131
+ color: #ffffff;
132
+ overflow: hidden;
133
+ text-overflow: ellipsis;
134
+ display: -webkit-box;
135
+ -webkit-line-clamp: 2;
136
+ -webkit-box-orient: vertical;
137
+ }
138
+
139
+ .t-agent-execute-card-tile-execute-button {
140
+ margin-left: auto;
141
+ line-height: 18px;
142
+ padding: 3px 12px;
143
+ font-size: 12px;
144
+ font-weight: 600;
145
+ color: #e36468;
146
+ background-color: #ffffff;
147
+ display: flex;
148
+ justify-content: center;
149
+ align-items: center;
150
+ border-radius: 18px;
151
+ }
152
+ }
153
+ }
154
+ }
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { DeviceInfoItem, SceneInfoItem, ChangeInfoItem } from '@ray-js/t-agent-plugin-assistant';
3
+ import './Expand.less';
4
+ export interface IOperations {
5
+ device: DeviceInfoItem[];
6
+ scene: SceneInfoItem[];
7
+ moreDevice: ChangeInfoItem[];
8
+ moreScene: ChangeInfoItem[];
9
+ more: ChangeInfoItem[];
10
+ }
11
+ interface ExpandProps {
12
+ operations?: IOperations;
13
+ tapDevice?: (e: any) => void;
14
+ tapScene?: (e: any) => void;
15
+ }
16
+ export default function Expand({ operations, tapDevice, tapScene, }: ExpandProps): React.JSX.Element;
17
+ export {};
@@ -0,0 +1,169 @@
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.map.js";
3
+ import { View, Text, Image } from '@ray-js/components';
4
+ import React from 'react';
5
+ import { SceneType } from '@ray-js/t-agent-plugin-assistant';
6
+ import Tabs from './Tabs';
7
+ import './Expand.less';
8
+ import bookmark from '../ExecuteCardTile/bookmark.png';
9
+ import lockPng from './lock.png';
10
+ import { useRenderOptions } from '../../hooks';
11
+ import { formatMessage } from '../../utils';
12
+ export default function Expand(_ref) {
13
+ var _operations$device, _operations$moreDevic, _operations$scene, _operations$moreScene, _operations$more;
14
+ let {
15
+ operations = {
16
+ device: [],
17
+ scene: [],
18
+ moreDevice: [],
19
+ moreScene: [],
20
+ more: []
21
+ },
22
+ tapDevice,
23
+ tapScene
24
+ } = _ref;
25
+ const {
26
+ i18nTranslate: t
27
+ } = useRenderOptions();
28
+ const deviceCount = (((_operations$device = operations.device) === null || _operations$device === void 0 ? void 0 : _operations$device.length) || 0) + (((_operations$moreDevic = operations.moreDevice) === null || _operations$moreDevic === void 0 ? void 0 : _operations$moreDevic.length) || 0);
29
+ const sceneCount = (((_operations$scene = operations.scene) === null || _operations$scene === void 0 ? void 0 : _operations$scene.length) || 0) + (((_operations$moreScene = operations.moreScene) === null || _operations$moreScene === void 0 ? void 0 : _operations$moreScene.length) || 0);
30
+ const moreCount = ((_operations$more = operations.more) === null || _operations$more === void 0 ? void 0 : _operations$more.length) || 0;
31
+ const tabs = [];
32
+ if (deviceCount > 0) {
33
+ var _operations$device2, _operations$moreDevic2;
34
+ tabs.push({
35
+ key: 'device',
36
+ title: t('t-agent.expand.tab.device'),
37
+ badge: deviceCount,
38
+ content: /*#__PURE__*/React.createElement(View, {
39
+ className: "t-agent-expand-device-list"
40
+ }, (_operations$device2 = operations.device) === null || _operations$device2 === void 0 ? void 0 : _operations$device2.map(device => {
41
+ return /*#__PURE__*/React.createElement(View, {
42
+ key: device.deviceId,
43
+ className: "t-agent-expand-device-item",
44
+ onClick: () => tapDevice === null || tapDevice === void 0 ? void 0 : tapDevice({
45
+ currentTarget: {
46
+ dataset: {
47
+ id: device.deviceId
48
+ }
49
+ }
50
+ })
51
+ }, /*#__PURE__*/React.createElement(Image, {
52
+ src: device.icon,
53
+ className: "t-agent-expand-device-icon"
54
+ }), /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(View, {
55
+ className: "t-agent-expand-device-info"
56
+ }, /*#__PURE__*/React.createElement(View, {
57
+ className: "t-agent-expand-device-name"
58
+ }, device.name), device.room && /*#__PURE__*/React.createElement(Text, {
59
+ className: "t-agent-expand-device-room"
60
+ }, "-", device.room)), /*#__PURE__*/React.createElement(Text, {
61
+ className: "t-agent-expand-device-status"
62
+ }, device.success ? t('t-agent.expand.execution.success') : t('t-agent.expand.execution.failed'))));
63
+ }), (_operations$moreDevic2 = operations.moreDevice) === null || _operations$moreDevic2 === void 0 ? void 0 : _operations$moreDevic2.map(device => /*#__PURE__*/React.createElement(View, {
64
+ key: device.id,
65
+ className: "t-agent-expand-device-item",
66
+ onClick: () => tapDevice === null || tapDevice === void 0 ? void 0 : tapDevice({
67
+ currentTarget: {
68
+ dataset: {
69
+ id: device.id
70
+ }
71
+ }
72
+ })
73
+ }, /*#__PURE__*/React.createElement(Image, {
74
+ src: bookmark,
75
+ className: "t-agent-expand-device-icon"
76
+ }), /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(View, {
77
+ className: "t-agent-expand-device-info"
78
+ }, /*#__PURE__*/React.createElement(View, {
79
+ className: "t-agent-expand-device-name"
80
+ }, formatMessage(t, 't-agent.expand.device.rename', {
81
+ oldName: device.fromData,
82
+ newName: device.toData
83
+ }))), /*#__PURE__*/React.createElement(Text, {
84
+ className: "t-agent-expand-device-status"
85
+ }, device.success ? t('t-agent.expand.execution.success') : t('t-agent.expand.execution.failed'))))))
86
+ });
87
+ }
88
+ if (sceneCount > 0) {
89
+ var _operations$scene2, _operations$moreScene2;
90
+ tabs.push({
91
+ key: 'scene',
92
+ title: t('t-agent.expand.tab.scene'),
93
+ badge: sceneCount,
94
+ content: /*#__PURE__*/React.createElement(View, {
95
+ className: "t-agent-expand-scene-list"
96
+ }, (_operations$scene2 = operations.scene) === null || _operations$scene2 === void 0 ? void 0 : _operations$scene2.map(scene => {
97
+ const isExecuteScene = scene.type === SceneType.EXECUTE;
98
+ const icon = isExecuteScene ? lockPng : bookmark;
99
+ return /*#__PURE__*/React.createElement(View, {
100
+ key: scene.sceneId,
101
+ className: "t-agent-expand-scene-item",
102
+ onClick: () => tapScene === null || tapScene === void 0 ? void 0 : tapScene({
103
+ currentTarget: {
104
+ dataset: {
105
+ id: scene.sceneId
106
+ }
107
+ }
108
+ })
109
+ }, /*#__PURE__*/React.createElement(Image, {
110
+ src: scene.icon || icon,
111
+ className: "t-agent-expand-scene-icon"
112
+ }), /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(View, {
113
+ className: "t-agent-expand-scene-name"
114
+ }, isExecuteScene ? t('t-agent.expand.scene.one-click') : t('t-agent.expand.scene.auto'), ' ', scene.name), /*#__PURE__*/React.createElement(Text, {
115
+ className: "t-agent-expand-scene-status"
116
+ }, scene.success ? t('t-agent.expand.execution.success') : t('t-agent.expand.execution.failed'))));
117
+ }), (_operations$moreScene2 = operations.moreScene) === null || _operations$moreScene2 === void 0 ? void 0 : _operations$moreScene2.map(scene => /*#__PURE__*/React.createElement(View, {
118
+ key: scene.id,
119
+ className: "t-agent-expand-scene-item",
120
+ onClick: () => tapScene === null || tapScene === void 0 ? void 0 : tapScene({
121
+ currentTarget: {
122
+ dataset: {
123
+ id: scene.id
124
+ }
125
+ }
126
+ })
127
+ }, /*#__PURE__*/React.createElement(Image, {
128
+ src: bookmark,
129
+ className: "t-agent-expand-scene-icon"
130
+ }), /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(View, {
131
+ className: "t-agent-expand-scene-name"
132
+ }, formatMessage(t, 't-agent.expand.scene.rename', {
133
+ oldName: scene.fromData,
134
+ newName: scene.toData
135
+ })), /*#__PURE__*/React.createElement(Text, {
136
+ className: "t-agent-expand-scene-status"
137
+ }, scene.success ? t('t-agent.expand.execution.success') : t('t-agent.expand.execution.failed'))))))
138
+ });
139
+ }
140
+ if (moreCount > 0) {
141
+ var _operations$more2;
142
+ tabs.push({
143
+ key: 'more',
144
+ title: t('t-agent.expand.tab.more'),
145
+ badge: moreCount,
146
+ content: /*#__PURE__*/React.createElement(View, {
147
+ className: "t-agent-expand-more-list"
148
+ }, (_operations$more2 = operations.more) === null || _operations$more2 === void 0 ? void 0 : _operations$more2.map(item => /*#__PURE__*/React.createElement(View, {
149
+ key: item.id,
150
+ className: "t-agent-expand-more-item"
151
+ }, /*#__PURE__*/React.createElement(Image, {
152
+ src: bookmark,
153
+ className: "t-agent-expand-more-icon"
154
+ }), /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(View, {
155
+ className: "t-agent-expand-more-name"
156
+ }, item.desc), /*#__PURE__*/React.createElement(Text, {
157
+ className: "t-agent-expand-more-status"
158
+ }, item.success ? t('t-agent.expand.execution.success') : t('t-agent.expand.execution.failed'))))))
159
+ });
160
+ }
161
+ return /*#__PURE__*/React.createElement(View, {
162
+ className: "t-agent-expand-container"
163
+ }, tabs.length > 0 ? /*#__PURE__*/React.createElement(Tabs, {
164
+ tabs: tabs,
165
+ defaultActiveKey: tabs[0].key
166
+ }) : /*#__PURE__*/React.createElement(View, {
167
+ className: "t-agent-expand-empty"
168
+ }, /*#__PURE__*/React.createElement(Text, null, t('t-agent.expand.no.details'))));
169
+ }
@@ -0,0 +1,135 @@
1
+ .t-agent-expand {
2
+ &-container {
3
+ padding: 16px;
4
+ background-color: #fff;
5
+ border-radius: 8px;
6
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
7
+ margin-top: 12px;
8
+ }
9
+
10
+ &-empty {
11
+ display: flex;
12
+ justify-content: center;
13
+ align-items: center;
14
+ min-height: 100px;
15
+ color: #999;
16
+ }
17
+
18
+ &-device {
19
+ &-list {
20
+ display: flex;
21
+ flex-direction: column;
22
+ gap: 12px;
23
+ }
24
+
25
+ &-item {
26
+ display: flex;
27
+ align-items: center;
28
+ padding: 12px;
29
+ background-color: #f5f5f5;
30
+ border-radius: 6px;
31
+
32
+ &:active {
33
+ opacity: 0.8;
34
+ }
35
+ }
36
+
37
+ &-icon {
38
+ width: 40px;
39
+ height: 40px;
40
+ border-radius: 12px;
41
+ margin-right: 5px;
42
+ }
43
+
44
+ &-info {
45
+ display: flex;
46
+ align-items: center;
47
+ }
48
+
49
+ &-name {
50
+ font-size: 14px;
51
+ font-weight: 500;
52
+ color: #333;
53
+ }
54
+
55
+ &-room {
56
+ font-size: 12px;
57
+ color: #666;
58
+ margin-left: 4px;
59
+ }
60
+
61
+ &-status {
62
+ font-size: 12px;
63
+ color: #0089ff;
64
+ }
65
+ }
66
+
67
+ &-scene {
68
+ &-list {
69
+ display: flex;
70
+ flex-direction: column;
71
+ gap: 12px;
72
+ }
73
+
74
+ &-item {
75
+ display: flex;
76
+ align-items: center;
77
+ padding: 12px;
78
+ background-color: #f5f5f5;
79
+ border-radius: 6px;
80
+
81
+ &:active {
82
+ opacity: 0.8;
83
+ }
84
+ }
85
+
86
+ &-icon {
87
+ width: 40px;
88
+ height: 40px;
89
+ border-radius: 12px;
90
+ margin-right: 5px;
91
+ }
92
+
93
+ &-name {
94
+ font-size: 14px;
95
+ font-weight: 500;
96
+ color: #333;
97
+ }
98
+
99
+ &-status {
100
+ font-size: 12px;
101
+ color: #0089ff;
102
+ }
103
+ }
104
+
105
+ &-more {
106
+ &-list {
107
+ display: flex;
108
+ flex-direction: column;
109
+ gap: 12px;
110
+ }
111
+
112
+ &-item {
113
+ display: flex;
114
+ align-items: center;
115
+ padding: 12px;
116
+ background-color: #f5f5f5;
117
+ border-radius: 6px;
118
+
119
+ &:active {
120
+ opacity: 0.8;
121
+ }
122
+ }
123
+
124
+ &-name {
125
+ font-size: 14px;
126
+ font-weight: 500;
127
+ color: #333;
128
+ }
129
+
130
+ &-status {
131
+ font-size: 12px;
132
+ color: #0089ff;
133
+ }
134
+ }
135
+ }
@@ -0,0 +1,16 @@
1
+ import React, { ReactNode } from 'react';
2
+ import './Tabs.less';
3
+ export interface TabItem {
4
+ key: string;
5
+ title: string;
6
+ content: ReactNode;
7
+ badge?: number;
8
+ }
9
+ export interface TabsProps {
10
+ tabs: TabItem[];
11
+ defaultActiveKey?: string;
12
+ onChange?: (key: string) => void;
13
+ className?: string;
14
+ }
15
+ declare const Tabs: React.FC<TabsProps>;
16
+ export default Tabs;
@@ -0,0 +1,39 @@
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.map.js";
3
+ import "core-js/modules/web.dom-collections.iterator.js";
4
+ import { View, Text } from '@ray-js/components';
5
+ import React, { useState, useCallback } from 'react';
6
+ import './Tabs.less';
7
+ const Tabs = _ref => {
8
+ var _tabs$;
9
+ let {
10
+ tabs,
11
+ defaultActiveKey,
12
+ onChange,
13
+ className = ''
14
+ } = _ref;
15
+ const [activeKey, setActiveKey] = useState(defaultActiveKey || ((_tabs$ = tabs[0]) === null || _tabs$ === void 0 ? void 0 : _tabs$.key) || '');
16
+ const handleTabClick = useCallback(key => {
17
+ setActiveKey(key);
18
+ onChange === null || onChange === void 0 || onChange(key);
19
+ }, [onChange]);
20
+ return /*#__PURE__*/React.createElement(View, {
21
+ className: "t-agent-tabs ".concat(className)
22
+ }, /*#__PURE__*/React.createElement(View, {
23
+ className: "t-agent-tabs-header"
24
+ }, tabs.map(tab => /*#__PURE__*/React.createElement(View, {
25
+ key: tab.key,
26
+ className: "t-agent-tabs-tab ".concat(activeKey === tab.key ? 't-agent-tabs-tab--active' : ''),
27
+ onClick: () => handleTabClick(tab.key)
28
+ }, /*#__PURE__*/React.createElement(Text, {
29
+ className: "t-agent-tabs-tab-title"
30
+ }, tab.title), tab.badge !== undefined && tab.badge > 0 && /*#__PURE__*/React.createElement(View, {
31
+ className: "t-agent-tabs-tab-badge"
32
+ }, tab.badge)))), /*#__PURE__*/React.createElement(View, {
33
+ className: "t-agent-tabs-content"
34
+ }, tabs.map(tab => /*#__PURE__*/React.createElement(View, {
35
+ key: tab.key,
36
+ className: "t-agent-tabs-pane ".concat(activeKey === tab.key ? 't-agent-tabs-pane--active' : 't-agent-tabs-pane--inactive')
37
+ }, tab.content))));
38
+ };
39
+ export default Tabs;
@@ -0,0 +1,72 @@
1
+ .t-agent-tabs {
2
+ width: 100%;
3
+
4
+ &-header {
5
+ display: flex;
6
+ border-bottom: 1px solid #e6e6e6;
7
+ margin-bottom: 16px;
8
+ }
9
+
10
+ &-tab {
11
+ position: relative;
12
+ padding: 12px 16px;
13
+ margin-right: 8px;
14
+ cursor: pointer;
15
+ transition: all 0.3s;
16
+
17
+ &:last-child {
18
+ margin-right: 0;
19
+ }
20
+
21
+ &--active {
22
+ color: #0089ff;
23
+ font-weight: 500;
24
+
25
+ &::after {
26
+ content: '';
27
+ position: absolute;
28
+ bottom: 0;
29
+ left: 0;
30
+ width: 100%;
31
+ height: 2px;
32
+ background-color: #0089ff;
33
+ }
34
+ }
35
+
36
+ &-title {
37
+ font-size: 14px;
38
+ }
39
+
40
+ &-badge {
41
+ position: absolute;
42
+ top: 4px;
43
+ right: 4px;
44
+ min-width: 16px;
45
+ height: 16px;
46
+ padding: 0 4px;
47
+ background-color: #ff4d4f;
48
+ border-radius: 8px;
49
+ color: #fff;
50
+ font-size: 12px;
51
+ line-height: 16px;
52
+ text-align: center;
53
+ }
54
+ }
55
+
56
+ &-content {
57
+ position: relative;
58
+ width: 100%;
59
+ }
60
+
61
+ &-pane {
62
+ width: 100%;
63
+
64
+ &--active {
65
+ display: block;
66
+ }
67
+
68
+ &--inactive {
69
+ display: none;
70
+ }
71
+ }
72
+ }
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import './index.less';
3
+ import { ChangeInfoItem, DeviceInfoItem, SceneInfoItem } from '@ray-js/t-agent-plugin-assistant';
4
+ import { TileProps } from '../../types';
5
+ import { IOperations } from './Expand';
6
+ export interface OperateCardTileData {
7
+ deviceInfo: DeviceInfoItem[];
8
+ sceneInfo: SceneInfoItem[];
9
+ changeInfo: ChangeInfoItem[];
10
+ }
11
+ export interface OperateCardTileProps extends TileProps {
12
+ data: OperateCardTileData;
13
+ /** 自定义详情内容渲染函数 */
14
+ renderDetail?: (props: {
15
+ operations: IOperations;
16
+ tapDevice: (e: any) => void;
17
+ tapScene: (e: any) => void;
18
+ show: boolean;
19
+ }) => React.ReactNode;
20
+ }
21
+ export default function OperateCardTile({ data, renderDetail }: OperateCardTileProps): React.JSX.Element | null;
@@ -0,0 +1,228 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import "core-js/modules/esnext.iterator.constructor.js";
3
+ import "core-js/modules/esnext.iterator.for-each.js";
4
+ import "core-js/modules/web.dom-collections.iterator.js";
5
+ import { Text, View } from '@ray-js/components';
6
+ import React, { useMemo, useState } from 'react';
7
+ import './index.less';
8
+ import { useRenderOptions } from '../../hooks';
9
+ import Expand from './Expand';
10
+ import { formatMessage } from '../../utils';
11
+ const handleDesc = (detail, t) => {
12
+ const {
13
+ device,
14
+ moreDevice,
15
+ scene,
16
+ moreScene,
17
+ more
18
+ } = detail;
19
+ const desc = [];
20
+ let deviceNum = device.length + moreDevice.length;
21
+ const sceneNum = scene.length + moreScene.length;
22
+ let homeNum = 0;
23
+ let roomNum = 0;
24
+ let groupNum = 0;
25
+ if (more.length) {
26
+ more.forEach(i => {
27
+ switch (i.type) {
28
+ case 'home':
29
+ homeNum += 1;
30
+ break;
31
+ case 'room':
32
+ roomNum += 1;
33
+ break;
34
+ case 'group':
35
+ groupNum += 1;
36
+ break;
37
+ case 'deviceRoom':
38
+ deviceNum += 1;
39
+ break;
40
+ default:
41
+ break;
42
+ }
43
+ });
44
+ }
45
+ if (deviceNum) {
46
+ desc.push(formatMessage(t, 't-agent.operate-card-tile.device.count', {
47
+ count: deviceNum
48
+ }));
49
+ }
50
+ if (sceneNum) {
51
+ desc.push(formatMessage(t, 't-agent.operate-card-tile.scene.count', {
52
+ count: sceneNum
53
+ }));
54
+ }
55
+ if (homeNum) {
56
+ desc.push(formatMessage(t, 't-agent.operate-card-tile.home.count', {
57
+ count: homeNum
58
+ }));
59
+ }
60
+ if (roomNum) {
61
+ desc.push(formatMessage(t, 't-agent.operate-card-tile.room.count', {
62
+ count: roomNum
63
+ }));
64
+ }
65
+ if (groupNum) {
66
+ desc.push(formatMessage(t, 't-agent.operate-card-tile.group.count', {
67
+ count: groupNum
68
+ }));
69
+ }
70
+ return formatMessage(t, 't-agent.operate-card-tile.description.format', {
71
+ items: desc.join(t('t-agent.operate-card-tile.description.separator'))
72
+ });
73
+ };
74
+ export default function OperateCardTile(_ref) {
75
+ let {
76
+ data,
77
+ renderDetail
78
+ } = _ref;
79
+ const {
80
+ deviceInfo = [],
81
+ sceneInfo = [],
82
+ changeInfo = []
83
+ } = data || {};
84
+ const {
85
+ i18nTranslate: t
86
+ } = useRenderOptions();
87
+ const [show, setShow] = useState(false);
88
+ const [showDetail, setShowDetail] = useState(false);
89
+ const tapDevice = e => {
90
+ const deviceId = e.currentTarget.dataset.id;
91
+ ty.openPanel({
92
+ deviceId,
93
+ fail: () => {
94
+ ty.showToast({
95
+ title: t('t-agent.operate-card-tile.open.device.failed'),
96
+ icon: 'error'
97
+ });
98
+ }
99
+ });
100
+ };
101
+ const tapScene = e => {
102
+ const sceneId = e.currentTarget.dataset.id;
103
+ ty.router({
104
+ url: "tuyaSmart://editScene?sceneId=".concat(sceneId, "&biz_type=ai_smart&action=edit"),
105
+ fail: () => {
106
+ ty.showToast({
107
+ title: t('t-agent.operate-card-tile.open.scene.failed'),
108
+ icon: 'error'
109
+ });
110
+ }
111
+ });
112
+ };
113
+ const {
114
+ operations
115
+ } = useMemo(() => {
116
+ let isShow = show;
117
+ const operations = {
118
+ device: [],
119
+ scene: [],
120
+ moreDevice: [],
121
+ moreScene: [],
122
+ more: []
123
+ };
124
+ if (deviceInfo !== null && deviceInfo !== void 0 && deviceInfo.length) {
125
+ deviceInfo.forEach(i => {
126
+ const {
127
+ intent
128
+ } = i;
129
+ switch (intent) {
130
+ case 'controlDevice':
131
+ isShow = true;
132
+ operations.device.push(i);
133
+ break;
134
+ default:
135
+ break;
136
+ }
137
+ });
138
+ }
139
+ if (sceneInfo !== null && sceneInfo !== void 0 && sceneInfo.length) {
140
+ sceneInfo.forEach(i => {
141
+ if (i.valid == null) {
142
+ i.valid = true;
143
+ }
144
+ const {
145
+ intent
146
+ } = i;
147
+ switch (intent) {
148
+ case 'queryScene':
149
+ case 'updateScene':
150
+ break;
151
+ case 'deleteScene':
152
+ if (i.success) {
153
+ isShow = true;
154
+ operations.scene.push(i);
155
+ }
156
+ break;
157
+ default:
158
+ isShow = true;
159
+ operations.scene.push(_objectSpread(_objectSpread({}, i), {}, {
160
+ displayType: 'execute'
161
+ }));
162
+ break;
163
+ }
164
+ });
165
+ }
166
+ if (changeInfo !== null && changeInfo !== void 0 && changeInfo.length) {
167
+ isShow = true;
168
+ changeInfo.forEach(i => {
169
+ switch (i.type) {
170
+ case 'scene':
171
+ operations.moreScene.push(i);
172
+ break;
173
+ case 'device':
174
+ operations.moreDevice.push(i);
175
+ break;
176
+ default:
177
+ {
178
+ let desc = '';
179
+ if (i.type === 'deviceRoom') {
180
+ desc = formatMessage(t, 't-agent.operate-card-tile.device.move.desc', {
181
+ device: i.fromData,
182
+ room: i.toData
183
+ });
184
+ } else {
185
+ desc = formatMessage(t, 't-agent.operate-card-tile.device.rename.desc', {
186
+ oldName: i.fromData,
187
+ newName: i.toData
188
+ });
189
+ }
190
+ i.desc = desc;
191
+ operations.more.push(i);
192
+ }
193
+ break;
194
+ }
195
+ });
196
+ }
197
+ if (isShow && !show) {
198
+ setShow(true);
199
+ }
200
+ return {
201
+ operations
202
+ };
203
+ }, [deviceInfo, sceneInfo, changeInfo, show, t]);
204
+ const desc = useMemo(() => handleDesc(operations, t), [operations, t]);
205
+ const toggleDetail = () => {
206
+ setShowDetail(!showDetail);
207
+ };
208
+ if (show) {
209
+ return /*#__PURE__*/React.createElement(View, {
210
+ className: "t-agent-scene-control-tile"
211
+ }, /*#__PURE__*/React.createElement(View, {
212
+ className: "t-agent-scene-control-tile-summary"
213
+ }, t('t-agent.operate-card-tile.operation.impact'), desc, /*#__PURE__*/React.createElement(Text, {
214
+ className: "t-agent-scene-control-tile-summary-detail",
215
+ onClick: toggleDetail
216
+ }, showDetail ? t('t-agent.operate-card-tile.hide.details') : t('t-agent.operate-card-tile.view.details'))), renderDetail && renderDetail({
217
+ operations,
218
+ tapDevice,
219
+ tapScene,
220
+ show: showDetail
221
+ }), showDetail && !renderDetail && /*#__PURE__*/React.createElement(Expand, {
222
+ operations: operations,
223
+ tapDevice: tapDevice,
224
+ tapScene: tapScene
225
+ }));
226
+ }
227
+ return null;
228
+ }
@@ -0,0 +1,18 @@
1
+ .t-agent-scene-control-tile {
2
+ transition: all 0.3s ease;
3
+ &-summary {
4
+ width: 100%;
5
+ display: flex;
6
+ align-items: center;
7
+ padding-top: 8px;
8
+ margin-top: 8px;
9
+ border-top: 1px solid var(--app-B3-N7);
10
+ font-size: 12px;
11
+ color: var(--app-B3-N3);
12
+ line-height: 18px;
13
+
14
+ &-detail {
15
+ color: var(--app-M4);
16
+ }
17
+ }
18
+ }
package/dist/tiles/map.js CHANGED
@@ -9,6 +9,8 @@ import RecommendationsTile from './RecommendationsTile';
9
9
  import CardTile from './CardTile';
10
10
  import WorkflowTile from './WorkflowTile';
11
11
  import DocumentsTile from './DocumentsTile';
12
+ import OperateCardTile from './OperateCardTile';
13
+ import ExecuteCardTile from './ExecuteCardTile';
12
14
  export const tileMap = {
13
15
  bubble: BubbleTile,
14
16
  image: ImageTile,
@@ -20,5 +22,7 @@ export const tileMap = {
20
22
  recommendations: RecommendationsTile,
21
23
  card: CardTile,
22
24
  workflow: WorkflowTile,
23
- documents: DocumentsTile
25
+ documents: DocumentsTile,
26
+ operateCard: OperateCardTile,
27
+ executeCard: ExecuteCardTile
24
28
  };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 用于处理多语言文本中的变量替换
3
+ * @param t i18n翻译函数
4
+ * @param key 多语言键名
5
+ * @param params 需要替换的变量对象,如 {name: '小明', age: 18}
6
+ * @returns 替换变量后的文本
7
+ *
8
+ * 使用示例:
9
+ * formatMessage(t, 'greet', {name: '小明'}) // 假设 'greet' 对应的文本是 "你好,{name}",将返回 "你好,小明"
10
+ */
11
+ export declare const formatMessage: (t: (key: string) => string, key: string, params?: Record<string, string | number>) => string;
@@ -0,0 +1,28 @@
1
+ import "core-js/modules/es.regexp.exec.js";
2
+ import "core-js/modules/es.string.replace.js";
3
+ import "core-js/modules/esnext.iterator.constructor.js";
4
+ import "core-js/modules/esnext.iterator.for-each.js";
5
+ import "core-js/modules/web.dom-collections.iterator.js";
6
+ /**
7
+ * 用于处理多语言文本中的变量替换
8
+ * @param t i18n翻译函数
9
+ * @param key 多语言键名
10
+ * @param params 需要替换的变量对象,如 {name: '小明', age: 18}
11
+ * @returns 替换变量后的文本
12
+ *
13
+ * 使用示例:
14
+ * formatMessage(t, 'greet', {name: '小明'}) // 假设 'greet' 对应的文本是 "你好,{name}",将返回 "你好,小明"
15
+ */
16
+ export const formatMessage = (t, key, params) => {
17
+ if (!params) {
18
+ return t(key);
19
+ }
20
+ let message = t(key);
21
+
22
+ // 替换所有的变量
23
+ Object.entries(params).forEach(_ref => {
24
+ let [paramKey, paramValue] = _ref;
25
+ message = message.replace("{".concat(paramKey, "}"), String(paramValue));
26
+ });
27
+ return message;
28
+ };
@@ -0,0 +1,2 @@
1
+ export declare function routeScene(sceneId: string): void;
2
+ export * from './formatMessage';
@@ -0,0 +1,13 @@
1
+ export function routeScene(sceneId) {
2
+ ty.router({
3
+ url: "tuyaSmart://editScene?sceneId=".concat(sceneId, "&biz_type=ai_smart&action=edit"),
4
+ fail: err => {
5
+ console.error('router fail', sceneId, err);
6
+ ty.showToast({
7
+ title: err.errorMsg || I18n.t('execute_fail'),
8
+ icon: 'error'
9
+ });
10
+ }
11
+ });
12
+ }
13
+ export * from './formatMessage';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/t-agent-ui-ray",
3
- "version": "0.1.0-beta-3",
3
+ "version": "0.1.0-beta-4",
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": "afafdb05637f3c9cb46ef3ef518319baa748199e"
44
+ "gitHead": "c637b234c10a43611ed395ce06b8d85f3f83bbce"
45
45
  }