@ray-js/t-agent-ui-ray 0.1.0-beta-3 → 0.1.0-beta-5
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 +1 -2
- package/dist/MessageInput/index.js +2 -4
- package/dist/contexts.d.ts +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +2 -1
- package/dist/hooks/useLongPress.js +40 -23
- package/dist/hooks/useTranslate.d.ts +2 -0
- package/dist/hooks/useTranslate.js +62 -0
- package/dist/i18n/strings.d.ts +499 -0
- package/dist/i18n/strings.js +498 -0
- package/dist/tiles/BubbleTile/index.js +2 -5
- package/dist/tiles/DividerTile/index.d.ts +8 -0
- package/dist/tiles/DividerTile/index.js +16 -0
- package/dist/tiles/DividerTile/index.less +26 -0
- package/dist/tiles/ExecuteCardTile/bookmark.png +0 -0
- package/dist/tiles/ExecuteCardTile/index.d.ts +10 -0
- package/dist/tiles/ExecuteCardTile/index.js +231 -0
- package/dist/tiles/ExecuteCardTile/index.less +154 -0
- package/dist/tiles/OperateCardTile/Expand.d.ts +17 -0
- package/dist/tiles/OperateCardTile/Expand.js +167 -0
- package/dist/tiles/OperateCardTile/Expand.less +135 -0
- package/dist/tiles/OperateCardTile/Tabs.d.ts +16 -0
- package/dist/tiles/OperateCardTile/Tabs.js +39 -0
- package/dist/tiles/OperateCardTile/Tabs.less +72 -0
- package/dist/tiles/OperateCardTile/index.d.ts +21 -0
- package/dist/tiles/OperateCardTile/index.js +226 -0
- package/dist/tiles/OperateCardTile/index.less +18 -0
- package/dist/tiles/OperateCardTile/lock.png +0 -0
- package/dist/tiles/map.js +7 -1
- package/dist/utils/formatMessage.d.ts +11 -0
- package/dist/utils/formatMessage.js +28 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +13 -0
- package/package.json +2 -2
|
@@ -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(() => {
|
|
@@ -13,13 +13,11 @@ import imageSvg from './icons/image.svg';
|
|
|
13
13
|
import videoSvg from './icons/video.svg';
|
|
14
14
|
import loadingSvg from './icons/loading.svg';
|
|
15
15
|
import closeCircleSvg from './icons/close-circle.svg';
|
|
16
|
-
import { useAttachmentInput, useChatAgent, useEmitEvent, useIsUnmounted, useOnEvent, useRenderOptions } from '../hooks';
|
|
16
|
+
import { useAttachmentInput, useChatAgent, useEmitEvent, useIsUnmounted, useOnEvent, useRenderOptions, useTranslate } from '../hooks';
|
|
17
17
|
import AsrInput from './AsrInput';
|
|
18
18
|
export default function MessageInput(props) {
|
|
19
19
|
const [moreOpen, setMoreOpen] = useState(false);
|
|
20
|
-
const
|
|
21
|
-
i18nTranslate: t
|
|
22
|
-
} = useRenderOptions();
|
|
20
|
+
const t = useTranslate();
|
|
23
21
|
const [text, setText] = useState('');
|
|
24
22
|
const [asrText, setAsrText] = useState('');
|
|
25
23
|
const attachmentInput = useAttachmentInput();
|
package/dist/contexts.d.ts
CHANGED
|
@@ -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'
|
|
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>;
|
package/dist/hooks/index.d.ts
CHANGED
package/dist/hooks/index.js
CHANGED
|
@@ -4,10 +4,8 @@ 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
|
-
import {
|
|
10
|
-
import { useChatAgent } from '.';
|
|
8
|
+
import { useChatAgent, useTranslate } from '.';
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
* 预定义动作类型
|
|
@@ -35,9 +33,7 @@ export function useLongPress() {
|
|
|
35
33
|
}
|
|
36
34
|
});
|
|
37
35
|
const agent = useChatAgent();
|
|
38
|
-
const
|
|
39
|
-
i18nTranslate: t
|
|
40
|
-
} = useRenderOptions();
|
|
36
|
+
const t = useTranslate();
|
|
41
37
|
const [screenSize, setScreenSize] = useState({
|
|
42
38
|
width: 0,
|
|
43
39
|
height: 0
|
|
@@ -67,10 +63,10 @@ export function useLongPress() {
|
|
|
67
63
|
action: () => {
|
|
68
64
|
const content = getMessageContent();
|
|
69
65
|
if (content) {
|
|
70
|
-
setClipboardData({
|
|
66
|
+
ty.setClipboardData({
|
|
71
67
|
data: content,
|
|
72
68
|
success: () => {
|
|
73
|
-
showToast({
|
|
69
|
+
ty.showToast({
|
|
74
70
|
title: t('t-agent.message.copy.success'),
|
|
75
71
|
icon: 'none'
|
|
76
72
|
});
|
|
@@ -88,13 +84,13 @@ export function useLongPress() {
|
|
|
88
84
|
label: t('t-agent.message.action.delete'),
|
|
89
85
|
action: () => {
|
|
90
86
|
if (typeof agent.removeMessage === 'function') {
|
|
91
|
-
showModal({
|
|
87
|
+
ty.showModal({
|
|
92
88
|
title: t('t-agent.message.delete.title'),
|
|
93
89
|
content: t('t-agent.message.delete.content'),
|
|
94
90
|
success: res => {
|
|
95
91
|
if (res.confirm) {
|
|
96
92
|
agent.removeMessage(message.id);
|
|
97
|
-
showToast({
|
|
93
|
+
ty.showToast({
|
|
98
94
|
title: t('t-agent.message.delete.success'),
|
|
99
95
|
icon: 'none'
|
|
100
96
|
});
|
|
@@ -112,8 +108,11 @@ export function useLongPress() {
|
|
|
112
108
|
label: t('t-agent.message.action.deleteByChannel'),
|
|
113
109
|
action: () => {
|
|
114
110
|
const channel = agent.session.get('AIAssistant.channel');
|
|
115
|
-
|
|
116
|
-
|
|
111
|
+
const {
|
|
112
|
+
removeMessageByChannel
|
|
113
|
+
} = agent.plugins.assistant;
|
|
114
|
+
if (typeof removeMessageByChannel === 'function') {
|
|
115
|
+
removeMessageByChannel(channel);
|
|
117
116
|
}
|
|
118
117
|
}
|
|
119
118
|
});
|
|
@@ -122,11 +121,20 @@ export function useLongPress() {
|
|
|
122
121
|
menuItems.push({
|
|
123
122
|
key: 'like',
|
|
124
123
|
label: t('t-agent.message.action.like'),
|
|
125
|
-
action: () => {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
124
|
+
action: async () => {
|
|
125
|
+
const {
|
|
126
|
+
feedback
|
|
127
|
+
} = agent.plugins.assistant;
|
|
128
|
+
if (typeof feedback === 'function') {
|
|
129
|
+
await feedback({
|
|
130
|
+
requestId: message.id,
|
|
131
|
+
type: 'like'
|
|
132
|
+
});
|
|
133
|
+
ty.showToast({
|
|
134
|
+
title: t('t-agent.message.like.success'),
|
|
135
|
+
icon: 'none'
|
|
136
|
+
});
|
|
137
|
+
}
|
|
130
138
|
}
|
|
131
139
|
});
|
|
132
140
|
break;
|
|
@@ -134,11 +142,20 @@ export function useLongPress() {
|
|
|
134
142
|
menuItems.push({
|
|
135
143
|
key: 'unlike',
|
|
136
144
|
label: t('t-agent.message.action.unlike'),
|
|
137
|
-
action: () => {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
145
|
+
action: async () => {
|
|
146
|
+
const {
|
|
147
|
+
feedback
|
|
148
|
+
} = agent.plugins.assistant;
|
|
149
|
+
if (typeof feedback === 'function') {
|
|
150
|
+
await feedback({
|
|
151
|
+
requestId: message.id,
|
|
152
|
+
type: 'unlike'
|
|
153
|
+
});
|
|
154
|
+
ty.showToast({
|
|
155
|
+
title: t('t-agent.message.unlike.success'),
|
|
156
|
+
icon: 'none'
|
|
157
|
+
});
|
|
158
|
+
}
|
|
142
159
|
}
|
|
143
160
|
});
|
|
144
161
|
break;
|
|
@@ -195,7 +212,7 @@ export function useLongPress() {
|
|
|
195
212
|
isClosing: false,
|
|
196
213
|
menuPosition: adjustedPosition
|
|
197
214
|
});
|
|
198
|
-
vibrateShort({
|
|
215
|
+
ty.vibrateShort({
|
|
199
216
|
type: 'light'
|
|
200
217
|
});
|
|
201
218
|
if (e.origin && e.origin.stopPropagation) {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
2
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
3
|
+
import { useRenderOptions } from './context';
|
|
4
|
+
import { useCallback } from 'react';
|
|
5
|
+
import strings from '../i18n/strings';
|
|
6
|
+
const keyRE = /^t-agent\./;
|
|
7
|
+
const langRE = {
|
|
8
|
+
'zh-Hans': /^zh([-_](hans|cn|zh))/i,
|
|
9
|
+
'zh-Hant': /^zh([-_](hant|tw|hk|mo))/i,
|
|
10
|
+
en: /^en([-_](us|gb))/i,
|
|
11
|
+
ja: /^ja([-_](jp))/i,
|
|
12
|
+
de: /^de([-_](de))/i,
|
|
13
|
+
fr: /^fr([-_](fr))/i,
|
|
14
|
+
es: /^es([-_](es))/i,
|
|
15
|
+
it: /^it([-_](it))/i
|
|
16
|
+
};
|
|
17
|
+
const keys = Object.keys(langRE);
|
|
18
|
+
const cache = new Map();
|
|
19
|
+
const normalizeLanguage = lang => {
|
|
20
|
+
if (langRE[lang]) {
|
|
21
|
+
return lang;
|
|
22
|
+
}
|
|
23
|
+
if (cache.has(lang)) {
|
|
24
|
+
return cache.get(lang);
|
|
25
|
+
}
|
|
26
|
+
for (const key of keys) {
|
|
27
|
+
if (langRE[key].test(lang)) {
|
|
28
|
+
cache.set(lang, key);
|
|
29
|
+
return key;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
cache.set(lang, 'en');
|
|
33
|
+
// 默认返回英文
|
|
34
|
+
return 'en';
|
|
35
|
+
};
|
|
36
|
+
const translateCache = new Map();
|
|
37
|
+
export const translateWith = (key, i18nTranslate) => {
|
|
38
|
+
if (translateCache.has(key)) {
|
|
39
|
+
return translateCache.get(key);
|
|
40
|
+
}
|
|
41
|
+
const result = i18nTranslate(key);
|
|
42
|
+
// result 全等于 key 说明没有翻译,使用内置翻译
|
|
43
|
+
if (result === key && keyRE.test(key)) {
|
|
44
|
+
var _strings$language;
|
|
45
|
+
let {
|
|
46
|
+
language
|
|
47
|
+
} = ty.getSystemInfoSync();
|
|
48
|
+
language = normalizeLanguage(language);
|
|
49
|
+
if ((_strings$language = strings[language]) !== null && _strings$language !== void 0 && _strings$language[key]) {
|
|
50
|
+
translateCache.set(key, strings[language][key]);
|
|
51
|
+
return strings[language][key];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
translateCache.set(key, result);
|
|
55
|
+
return result;
|
|
56
|
+
};
|
|
57
|
+
export const useTranslate = () => {
|
|
58
|
+
const {
|
|
59
|
+
i18nTranslate
|
|
60
|
+
} = useRenderOptions();
|
|
61
|
+
return useCallback(key => translateWith(key, i18nTranslate), [i18nTranslate]);
|
|
62
|
+
};
|